How does the subclass Dog inherit the variable legs with the value of 4 from the superclass Animal - Java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

10th May 2019, 2:54 AM
Shak 240
Shak 240 - avatar
2 Answers
+ 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.
10th May 2019, 3:53 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 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.
10th May 2019, 10:32 PM
Denise Roßberg
Denise Roßberg - avatar