Java foundation------> Inheritance---> Properties (two ways to invoke the same property of the parent class in a subclass)

Source: Internet
Author: User
Tags inheritance

In today's succession review, I have a new insight into the attributes of inheritance------> Subclass inherits the parent class, inherits the parent class's methods and properties, and looks at the following figure

Inheritance---> Properties (two ways to call the parent class with the same name in a subclass) ">


As you can see from the diagram above, even if the subclass is an empty shell, he gets to the parent class's property name and Method Test () from the parent class.


But the next thing I'm talking about is a little focus---> in inheritance, subclasses inherit the attributes of the parent class and inherit methods differently

---> Parent properties cannot be overridden, are invoked only, the parent-class method can be overridden, or can be invoked

---> When a subclass has a property with the same name as the parent class, the Parent property is hidden, and when the property is invoked in a polymorphic state, the parent class attribute subclass property is hidden, and the method is not hidden and, once overridden, can only be invoked in the subclass by using super


Next, two ways to invoke a property of the parent class with the same name in the subclass (that is, to activate the hidden parent class property in the subclass)


Inheritance---> Properties (two ways to call the parent class with the same name in a subclass) ">


Summary: In inheritance, attributes are not overridable and will only be hidden

Method will be overridden and will not hide

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.