构造代码块作用:https://blog.csdn.net/hspingcc/article/details/54893853
package com.spring.partise;
class A{
A(){
System.out.println("无参构造方法");
}
A(String str){
System.out.println("带参数构造方法");
}
static{
System.out.println("静态代码块");
}
{
System.out.println("构造代码块");
}
}
public class helllo {
public static void main(String[] args) throws Exception {
A a = new A();
System.out.println("---------------------------");
A b = new A("test");
}
}
输出:
静态代码块
构造代码块
无参构造方法
---------------------------
构造代码块
带参数构造方法