给定如下代码: class Alpha { static String s = " "; protected Alpha() { s += "alpha "; } } class SubAlpha extends Alpha { private SubAlpha() { s += "sub "; } } public class SubSubAlpha extends Alpha { private SubSubAlpha() { s += "subsub "; } public static void main(String[] args) { new SubSubAlpha(); System.out.println(s); } } 运行结果为?().
A: subsub
B: sub subsub
C: alpha subsub
D: alpha sub subsub
A: subsub
B: sub subsub
C: alpha subsub
D: alpha sub subsub
举一反三
- 以下代码调试结果 class Base {} class Sub extends Base {} public class CEx{ public static void main(String argv[]){ Base b = new Base(); Sub s = (Sub) b; } }
- 阅读以下代码: public class foo{ public static void main (String[] args){ String s; System.out.println("s=" + s); 输出结果应该是
- 读代码:public class foo {static String s;public static void main (String[]args) {System.out.println (“s=” + s);}}结果是
- 给定如下一个 Java源文件 Child.java ,编译并运行 Child.java,以下结果正确的是。 class Parent1 { Parent1(String s) { System.out.println(s); } } class Parent2 extends Parent1 { Parent2() { System.out.println("parent2"); } } public class Child extends Parent2 { public static void main(String[] args) { Child child = new Child(); } }
- 给定java代码,如下:编译运行,结果是。 Public static void main(String[]) args) { String s; System.out.println(“s=”+s); }