JAVA class and instance initialization Initialization

First, the class initialization procedure

1, to create an instance of a class you need to create and load

     Class (1) main method where the need to load and instantiate

2, a subclass to initialize, you need to initialize the parent class

3, a class initialization is performed <clinit> method

      (1) <clinit> () method of assigning a static block code and displays a static class variables.

      (2) static class variable assignment and hippocampus static block of code execution order from top to bottom

      (3) <clinit> () method is executed only once

 

Second, instance initialization process (when the parent, the parent class to begin initialization)

1, initialization is executed example <init> () method

       (1) <init> () method may have a plurality of overload, there are several constructors have several <init> method

       (2) <init> () method to display the code assigned by the block non-static and non-static instance variables, configuration code corresponding to the composition

    (3) non-static instance variables are displayed and non-static assignment of code block execution order from top to bottom, the last execution code constructor

    (4) Each instance of the object created, call the corresponding constructor is performed corresponding <init> method

    (5) The first line of <init> method is super () or super (argument list), i.e., corresponding to parent <init> method

 

Note: If a subclass overrides the method of the parent class, subclass object by calling must be rewritten subclass code

        Non-static method call object is this default

        This object is an object in the constructor or <init> method is being created

Guess you like

Origin www.cnblogs.com/pxblog/p/11567790.html