Summary of Niuke.com Java Wrong Questions (5)

table of Contents

1. Inheritance

Two, static keyword

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:

  1. Parent class static code block
  2. Subclass static code block
  3. Parent class structure code block
  4. Parent class constructor
  5. Subclass construction code block
  6. Subclass construction method

Summary: first static and then non-static, first parent class and then child class.

 

 

Guess you like

Origin blog.csdn.net/weixin_39478524/article/details/115046732