Discussion on the inheritance of static variables and static methods in Java

Source: Internet
Author: User

Discussion on the inheritance of static variables and static methods in Java

If the learning is not clear or unclear, is to do some tests, and try it yourself, this time I will do a static variable inheritance and static method of inheritance problems test.

First, I'll build a parent class:

So I'm building a sub-class:

When these are all ready, I create the object for the subclass and then use the class name. static/static methods and object names. static/static variables test the results of their output.

Such output types are:

So the result I output is:

so to summarize:

1. The static and static methods in the subclass are called by the class name, and when the parent class is the same as the child class, the subclass hides the same static and static methods in the parent class, and if there are no static and static methods in the subclass that are identical to its parent class, the static and static methods that the subclass inherits from its parent class are displayed.

2. Create objects from subclasses to call static and static methods in subclasses with object names, except static and static methods that are not in the parent class, and display static and static methods for their subclasses. Otherwise, the final display must be a static variable and a static method from where the parent class is referenced.

Discussion on the inheritance of static variables and static methods in Java

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.