A: 输出:TestA
B: 输出:TestB
C: 输出:TestA TestB
D: 编译错误
举一反三
- 给定Java代码如下所示,则编译运行后,输出结果是。 class Parent { public void count() { System.out.println(10%3); } } public class Child extends Parent{ public void count() { System.out.println(10/3); } public static void main(String args[]) { Parent p = new Child(); p.count(); } }
- 中国大学MOOC: 下列代码中构造方法的返回类型是()public class Village { Village () { System .out .println(“hiding in Village”) ; } public static void main( String args [ ]) { Village c =new Village ( ) ;}class Village { public static void main( String args [ ]) { Village c =new Village ( ) ; } Village () { System .out .println(“hiding in Village”) ; } }
- interface A{ void x(); } class B implements A{ public void x(){} public void y(){} } class C extends B{ public void x(){System.out.println("C");} } public class Test{ public static void main(String args[]){ B b=new B(); B c=new C(); b.x(); c.y(); } } A: 程序运行错误 B: 程序没有输出结果 C: 程序输出C。 D: class B implements A 编译错误 E: c.y();编译错误
- 下列的程序的运行结果是( )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 foo{ public static void main (String[] args){ String s; System.out.println("s=" + s); 输出结果应该是
内容
- 0
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"); } }
- 1
下面程序的运行结果是public class Demo { public static void main(String[] args) { new Object(){ public void show(){ System.out.println("helloworld"); } }.show(); }} A: 什么也不输出 B: helloworld C: 编译报错 D: 编译通过,运行报错
- 2
下列程序运行结果是( ) 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"); } }
- 3
编译并运行下面的程序,结果是 public class A { public static void main(String args[]) { B b = new B(); b.test(); } void test() { System.out.print("A"); } } class B extends A { void test() { super.test(); System.out.println("B"); } }
- 4
请说出下列程序的输出结果。 class Cry { public void cry() { System.out.println("大家好"); } } public class E { public static void main(String args[]) { Cry hello=new Cry() { public void cry() { System.out.println("大家好,祝工作顺利!"); } }; hello.cry(); } }