阅读下面的程序,输出结果是()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: 编译错误
A: 5
B: 8
C: 7
D: 编译错误
举一反三
- 请写出下列程序的输出结果。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) ;}}
- 下列程序的执行结果是 public class TestDemo { public void fun() { static int i = 0; i++; System.out.println(i); } public static void main(String args[]) { Demo d = new Demo(); d.fun(); } }
- 对于一下程序,其运行结果为 class Base{ public Base(){ System.out.print("C"); } } class Base2 extends Base{ public Base2(){ System.out.print("B"); } } public class TestDemo extends Base2{ int m=1; public TestDemo(){ System.out.println("A"); } public static void main(String args[]){ TestDemo t = new TestDemo(); } }
- 中国大学MOOC: 下列程序运行结果是( )public class demo { public static void main(String[] args) { int x=30; int[] numbers=new int[x]; x=60; System.out.println(numbers.length); }}
- 18 下列程序的执行结果是?( ) public class TestDemo { public void fun() { static int i = 0; i++; System.out.println(i); } public static void main(String args[]) { Demo d = new Demo(); d.fun(); } } A: 编译错误 B: 0 C: 1 D: 运行成功,但不输出