Initialize block
Java uses constructors to complete state initialization, similar to constructors for initializing blocks
When you create a Java object, you always call the initialization block first, and if you have more than one block, it executes sequentially in order, and initialization is always performed implicitly when the Java object is created and
Constructor before executing
public class Person {{int a=6;if (a>4) {System.out.println ("initialization block for person: local variable greater than 4");//Note this is a local variable}}{ System.out.println ("The second initialization block of person");//Although it is possible to define two initialization blocks, there is no OVA with}public person () {System.out.println ("no argument constructor for person");} public static void Main (string[] args) {new person ();}} Initialization block for person: second initialization block with local variable greater than 4person no parameter constructor
Initialization of Java Review