abstract class BaseClass { public virtual void MethodA() { } public virtual void MethodB() { } } class Class1: BaseClass { public void MethodA(string arg){ } public override void MethodB(){ } } class Class2: Class1 { new public void MethodB(){ } } class MainClass { public static void Main(string[] args) { Class2 o = new Class2(); Console.WriteLine(o.MethodA()); } } 请问,o.MethodA调用的是
A: BaseClass.MethodA
B: Class2.MethodA
C: Class1.MethodA
D: 都不是
A: BaseClass.MethodA
B: Class2.MethodA
C: Class1.MethodA
D: 都不是
举一反三
- 以下程序的运行结果是______ abstract class class1{abstract void method1();}class class2 extends class1{public void method1(){ System.out.println("子类");}}public class MainClass{public static void main(String args[]){class1 ac=new class2();ac.method1();}}
- class A{ public void method(){} public void methodA(){}} class B extends A{ public void method(){} public void methodB(){} }<br/>则若有 A a = new B();a.methodB();下列说法正确的是() A: 执行类A的方法method B: 执行类B的方法methodB C: 编译通过,无法执行 D: 编译出错
- 请说出下列程序的输出结果_____________,_____________。import java.io.IOException;public class E {public static void main(String args[]){try { methodA();}catch(IOException e){System.out.print("你好");return;}finally {System.out.println("thanks");}}public static void methodA() throws IOException{throw new IOException();}}
- 以下语句能顺利通过编译: abstract class class1 { } public class mainClass { public static void main(String args[]) { class1 cs1=new class1(); } } 。()
- 给出下列程序的输出结果。import java.io.IOException;public class E {public static void main(String args[]){int m =10;try {methodA();m = 100;}catch(IOException e){m = 1000;}System.out.println(m);}public static void methodA() throws IOException{throw new IOException();}}