The initialization sequence

Three principles:

1, the variable prior to the method

2, before the static non-stationary (static constructor method)

3, the parent class before the subclass. (To be generated when a new subclass object parent object, which is packaged within an object subclass of this subclass is the reason using the parent class method).

Added: static initialization is only done when necessary, if it does not create an object and does not call static variables, static variables will not be created.

process:

 Object initialization:

  1. Subclass constructor first stack, the default initialization
  2. Super class constructor to the parent, the parent class constructor stack. If the parent class constructor method to be overwritten, the operating method of the subclass back. Parent class constructor after initialization is complete the stack. (Equivalent runs out super () statement)
  3. Subclass explicitly initialize
  4. Initialization code block structure
  5. Subclass constructor method

 

 

Published 38 original articles · won praise 6 · views 1900

Guess you like

Origin blog.csdn.net/weixin_43827227/article/details/104893523