A: 程序运行错误
B: 程序没有输出结果
C: 程序输出C。
D: class B implements A 编译错误
E: c.y();编译错误
举一反三
- 编译并运行下面的程序,结果是 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"); } }
- 下列代码编译和运行的结果是()。 public class A { public void start() { System.out.println("TestA"); } } public class B extends A { public void start() { System.out.println("TestB"); } public static void main(String[] args) { ((A) new B()).start(); } } A: 输出:TestA B: 输出:TestB C: 输出:TestA TestB D: 编译错误
- 阅读下面的程序,输出结果是()public class TestDemo{int m=5;public void some(int x){m=x;}public static void main(String args[]) {new Demo().some(7);}}class Demo extends TestDemo{int m=8;public void some(int x) {super.some(x);System.out.println(m);}} A: 5 B: 8 C: 7 D: 编译错误
- 下列哪个方法可用于创建一个可运行的类X? A: public class X implements Runnable{ public void run(){......} } B: public class X implements Thread{ public void run(){......} } C: public class X implements Thread{ public int run(){......} } D: public class X extends Runnable{ public void run(){......} }
- 阅读下列程序,请写出该程序的输出结果。 class B{ int b; B(int x){b=x;System.out.println("b="+b); } } class A extends B{ int a; A(int x,int y){ super(x); a=y; System.out.println("b="+b+",a="+a); } } public class a32{ public static void main(String[]args){ A obj=new A(1,2); } }
内容
- 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); } }