代码案例如下所示
class A{
public static int value = 134;
static{
System.out.println("A");
}
}
class B extends A{
static{
System.out.println("B");
}
}
public class Demo {
public static void main(String args[]){
int s = B.value;
System.out.println(s);
}
}
A
B
134
A
134
如何做才能打印a这种结果呢?
class A{
public static int valueA = 134;
static{
System.out.println("A");
}
}
class B extends A{
public static int valueB = 245;
static{
System.out.println("B");
}
}
public class Demo {
public static void main(String args[]){
int s = B.valueB;
System.out.println(s);
}
}
A
B
245
public static int value1 = 5;
public static int value2 = 6;
static{
value2 = 66;
}
原文:http://blog.51cto.com/11359966/2335676