Whether the member variables of the parent class in the inheritance will be overwritten by the subclasses of Java

Source: Internet
Author: User

The parent class int num = 7;
Subclass int num = 9;
Will the parent class be overwritten by the quilt class?

Here are two examples:

A first example:

A second example:



The difference between these two examples is that there is only one sentence that proves that when a subclass inherits from a parent class, a member variable with the same name is a member of the parent class by default.
The variable is masked if you want to invoke the member variable of the parent class, use the Super keyword

Whether the member variables of the parent class in the inheritance will be overwritten by the subclasses of Java

Related Article

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.