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.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>