构造块:用{}括起来的内容,放在类的构造函数之前,调用构造函数之前会执行
静态代码块:static {},调用构造函数之前会执行,且只会执行一次
{
System.out.println("这是构造块");
}
static {
System.out.println("这是静态代码块");
}
public Book(String name , String auther , String ISBN){
this.name = name;
this.auther = auther;
this.ISBN = ISBN;
}
输出:这是静态代码块
这是构造块