Answer the question
In order to leave comments, you need to log in
What are the ways to pass a variable from parent to child class?
I'm having a problem passing the value of a variable from parent to child class.
As I understood property values are not inherited.
The constants don't fit.
With a DB and files of a configuration too not a variant.
Answer the question
In order to leave comments, you need to log in
judging by the correspondence, you have class A and class B, which is the heir of A, that is, B: A
has 2 objects of class A and B,
you change something in the object from A and want to see something in the object from B, the
answer is no , you can’t do that. Either you need to build the architecture correctly, advice was in the answers of Viktor Gogilchin and Yuri Vitkovsky
What is the difference between private and protected, do you understand?
Use the magic word super =)
Parent class:
public class Parent {
private String valueForPass = "some value";
protected final String getValueForPass() {
return valueForPass;
}
}
public class Child extends Parent {
private String myOtherValue = super.getValueForPass();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question