table of Contents
Three, the loading order of the class (the second time wrong)
1. Inheritance
Analysis:
Note: Extension is extends, which is inheritance
Java only supports single inheritance, and multiple inheritance can be achieved in the following ways:
- Implement multiple interfaces
- Extends a class to implement one or more interfaces
- Inherit other classes through inner classes
Two, static keyword
Analysis:
Variables modified by static are called static variables, and static variables belong to the entire class.
Local variables belong to methods and are only valid within that method, so static cannot modify local variables .
So the program has a compilation error! ! ! !
Three, the loading order of the class (the second time wrong)
Analysis:
Class loading order:
- Parent class static code block
- Subclass static code block
- Parent class structure code block
- Parent class constructor
- Subclass construction code block
- Subclass construction method
Summary: first static and then non-static, first parent class and then child class.