代码案例如下所示
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;
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。