• 2022-06-08
    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();编译错误
  • B

    举一反三

    内容

    • 0

      (6-6)请阅读程序,写出程序运行结果。 class Test{ static int x=10; int y=99; { y=y+10; } static { x=x+5; } { y=y+10; } static { x=x+5; } public Test() {//构造方法 x=x+5; } { System.out.println(x*y); } } public class Demo11 { public static void main(String[] args) { Test t1=new Test(); Test t2=new Test(); } }

    • 1

      请写出下列程序的输出结果。class A{public int f(int x) {return x+1;}}class B extends A{public int f(int x){return x*x;}}public class E{public static void main(String args[]){A a=new B();int m=a.f(10);System. out. println(m) ;}}

    • 2

      下列哪个方法可用于创建一个可运行的类() A: public class X implements Runnable{public void run() {……}} B: public class X extends Thread{public void run() {……}} C: public class X extends Thread{public int run() {……}} D: public class X implements Runnable{protected void run() {……}}

    • 3

      请阅读下面的程序,写出最终的结果: interface Inter { public void show(); } abstract class AbstractInter implements Inter { public void show() { System.out.println("AbstractInter show()"); } } class InterImpl extends AbstractInter { public void show() { System.out.println("InterImpl show()"); } } public class InterImplTest { public static void main(String[] args) { InterImpl i = new InterImpl(); i. show(); } }

    • 4

      执行下列程序,输出结果为()。 public class B{ public static void main(String[] args) { int x = 5; double y = 10.5f; float z = (float)(x*y); System.out.println(z); } }