0
How does the subclass Dog inherit the variable legs with the value of 4 from the superclass Animal - Java
How does the subclass Dog inherit the variable legs with the value of 4 from the superclass Animal, when the variable legs doesn't store any value in the superclass. Where is it inheriting the 4 from? Am I missing something
2 odpowiedzi
+ 5
Hi.
I don't understand your question properly. Could you show me a reference to that inheritance code?
And also please specifiy which language you are using.
+ 2
You mean this lesson?
https://www.sololearn.com/learn/Java/2163/
The 4 is not inherit. Dog inherits only the variable legs. But have a look on the constructor of the Class Dog:
public Dog(){
legs = 4;
}
If you create an object Dog, the constructor is called and legs is setted to 4.