The order of execution of the code block and a constructor

Code demonstrates:


	public Person(String name, int age) {
		this.name = name;
		this.age = age;
		
		System.out.println("我是构造方法");
	}
	
	{
		
		System.out.println("我是构造代码块");
	}
	
	{
		
		System.out.println("我是静态代码块");
	}
	private String name;
	private int age;
	

The main method of execution:

public static void main(String[] args) {
		new Person("zhangsan", 18);
		
	}

Results of the:

Guess you like

Origin blog.csdn.net/qq_36897901/article/details/81197235