Inheritance of static variables and static methods in Java

Source: Internet
Author: User

Summarize:

1. Static variables and static methods say inheritance is not accurate, static methods and variables are the methods and variables belonging to the class. Subclasses also belong to the superclass, such as manage extends employee, then manage is also an employee, so subclasses can call static variables and methods that belong to the superclass. Notice that the subclass calls the static methods and variables of the superclass rather than the static methods and variables that inherit from the Super class. But if there are static methods and variables with the same name in the subclass, then the subclass itself is called, because the static and static methods of the subclass hide the static methods and variables of the parent class.

2. If a variable and method with the same name is not defined in the subclass, call the subclass name. static method/variable called the parent class method and variable

3,. If the subclass has only a static variable with the same name defined, and no static method with the same name as the parent class is called, the "subclass name. Static method" is called when the static method of the parent class is invoked, and the static variable in the static method is also the parent class (such as note [1] in the program)

4. If a child class defines a static variable with the same name as the parent class and a static method with the same name as the parent class, the call to the "subclass name. Static method" is completely unrelated to the parent class, and the static variable inside is also a subclass (such as note [2] in the program)

Http://www.cnblogs.com/gold-worker/archive/2012/09/27/2706232.html

Inheritance of static variables and static methods in Java (goto)

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.