Even if you don’t write the 3 sentences in the main method, it will execute 5 1 10 6 because the class where the main method is located needs to be loaded and initialized first
The execution sequence is as follows: first initialize the parent class and then initialize the subclass
Static instance variables display assignments and static code block codes are executed sequentially from top to bottom (according to the order of writing)
The instantiation method of the subclass:
(1) super() (foremost)
(2)i=test()
(3) Non-static code blocks of subclasses
(4) No-argument construction of subclasses (final)
The instantiation method of the parent class:
(1) super() (foremost)
(2) i=test() (Note: the method rewritten by the subclass output here)
(3) Non-static code blocks of the parent class
(4) The parameterless construction of the parent class (finally)
Non-static instance variables display assignments and non-static code block codes are executed sequentially from top to bottom (according to the writing order)
Each time an instance object is created, the corresponding constructor is called, and the corresponding init method is executed