请问下面这一段代码的执行结果是什么?
public class Demo {
private int a = 10;
{
a = 20;
}
public Demo(int a){
this.a = a;
}
public static void main(String[] args) {
Demo demo = new Demo(30);
System.out.println(demo.a);
}
}
如果我把代码的顺序调换成如下所示,请问编译期间会报错吗?不会的话,那他的结果又是什么?
public class Demo {
{
a = 20;
}
public Demo(int a){
this.a = a;
}
public static void main(String[] args) {
Demo demo = new Demo(30);
System.out.println(demo.a);
}
private int a = 10;
}



