场景一:求b的值
public class OrderDemo {
private static int b=0;
static {
b=1;
}
public static void main(String[] args) {
System.out.println(b);
}
}
场景二:求b的值
public class OrderDemo {
static {
b=1;
}
private static int b=0;
public static void main(String[] args) {
System.out.println(b);
}
}
场景三:求a的值
public class OrderDemo {
private int a=0;
{
a=1;
}
public static void main(String[] args) {
System.out.println(new OrderDemo().a);
}
}
场景四:求a的值
public class OrderDemo {
{
a=1;
}
private int a=0;
public static void main(String[] args) {
System.out.println(new OrderDemo().a);
}
}
场景五:求a的值
public class OrderDemo {
public OrderDemo() {
a = 10;
}
{
a=1;
}
private int a=0;
public static void main(String[] args) {
System.out.println(new OrderDemo().a);
}
}
总结