Explain in detail the relationship between properties, methods and objects in Java inheritance
As we all know, subclass inheritance and parent class are type inheritance, including properties and methods! If the method signatures in the subclass and parent class are the same, it is called overwrite! If the properties of the child class and the parent class are the same, the parent class will hide its own properties!
But if I use the reference created by the parent and child classes to point to the object created by the child class, what is the result of the property value or method in the child class object called by the parent class reference?
Look at the code:
The returned result is: Jack, rose, Jack, Jack
The reason is: in Java, attributes are bound to types and methods are bound to objects!
The article is very simple, but it also has certain practical value. I hope it will be helpful to everyone's study.