代碼案例以下所示php
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; }