为什么不能用static修饰这个初始化块?
public class HelloWorld {
String name1;
String name2;
static String name3;
public HelloWorld(){
{
name1="周杰伦";
System.out.println("偶像1"+name1);
}
{
name2="张学友";
System.out.println("偶像2"+name2);
}
static {
name3="王力宏";
System.out.println("偶像3"+name3);
}
}
public static void main(String[] args){
HelloWorld hello=new HelloWorld();
System.out.println("name1:"+hello.name1);
System.out.println("name2:"+hello.name2);
System.out.println("name3:"+name3);
HelloWorld hello2=new HelloWorld();
}
}
谢谢了~