1 Public classInstanceinitializer {2 Private inti =1;3 Private intGeti () {4 returni;5 }6 Private intj =Geti ();7 8 9 PublicInstanceinitializer ()Ten { Onei =2; A } - Public Static voidMain (string[] args) { -Instanceinitializer II =NewInstanceinitializer (); theSystem. out. println (II.J); -System. out. println (II.I); - } -}
The results of the above program operation:
1 Public classInstanceinitializer {2 Private inti = 1;3 Private intj =Geti ();4 Private intGeti () {5 returni;6 }7 8 9 Ten PublicInstanceinitializer () One { Ai = 2; - } - Public Static voidMain (string[] args) { theInstanceinitializer II =NewInstanceinitializer (); - System.out.println (II.J); - System.out.println (ii.i); - } +}
The results of the above program operation:
1 Public classInstanceinitializer {2 PublicInstanceinitializer ()3 {4i = 2;5 }6 Private inti = 1;7 Private intj =Geti ();8 Private intGeti () {9 returni;Ten } One A Public Static voidMain (string[] args) { -Instanceinitializer II =NewInstanceinitializer (); - System.out.println (II.J); the System.out.println (ii.i); - } -}
The results of the above program operation:
1 Public classInstanceinitializer {2 Private intJ=Geti ();3 private int i = 1; 4 PublicInstanceinitializer ()5 {6i = 2;7 }8 Private intGeti () {9 return i; Ten } One A Public Static voidMain (string[] args) { -Instanceinitializer II =NewInstanceinitializer (); - System.out.println (II.J); the System.out.println (ii.i); - } -}
The results of the above program operation:
The above procedure, because when the instance variable j is defined, the dispatched function needs a copy of the other instance variable I, but at this time the instance variable is not defined and initialized, so the function failed to be dispatched at this time.
The comparison results show that: 1. Instance variable definition, 2. initialization, 3. A function definition called for initialization of an instance variable contains an instance variable 4 that has been successfully defined and initialized. The definition of a constructor is
The basic order in which programs are edited and run.
That is, the program is initialized in the order of the instance variables in your writing program. (class variables are first defined and initialized)
The reciprocal assignment of an instance variable is a copy, not a reference.
The sequence of program initiation, and the understanding of instance variables assigned to each other and transferred copies