下面程序的运行结果是public class Demo { public static void main(String[] args) { new Object(){ public void show(){ System.out.println("helloworld"); } }.show(); }}
A: 什么也不输出
B: helloworld
C: 编译报错
D: 编译通过,运行报错
A: 什么也不输出
B: helloworld
C: 编译报错
D: 编译通过,运行报错
举一反三
- 下列的程序的运行结果是( )public class Example { public static void main(String[] args) { new Father () { public void show() { System.out.println("helloworld"); } }.show(); }}class Father { public void show() { System.out.println("hellofather"); }} A: hellofather B: helloworld C: 编译报错 D: 编译通过,运行报错
- 下列程序运行结果是( ) public class Demo { public static void main(String[] args) { Object obj=new Father(){ public void show(){ System.out.println("helloworld"); } }; obj.show(); } } class Father{ public void show(){ System.out.println("hello father"); } }
- 下列程序运行结果是 public class Demo { public static void main(String[] args) { Object obj=new Father(){ public void show(){ System.out.println("helloworld"); } }; obj.show(); } } class Father{ public void show(){ System.out.println("hello father"); } }
- 阅读下面的程序,分析代码是否能够编译通过,如果能编译通过,请列出运行的结果。否则请说明编译失败的原因。 public class Demo { public static void main(String[] args) { new Object(){ public void show(){ System.out.println("helloworld"); } }.show(); } }
- public class Example { public static void main(String[] args) { new Father () { public void show() { System.out.println("helloworld"); } }.show(); } } class Father { public void show() { System.out.println("hellofather"); } }