下列代码输出为( ):
class Father{
public void F() { Console.Write("A.F"); }
public virtual void G() { Console.Write("A.G"); }
}
class Son: Father{
new public void F() { Console.Write("B.F"); }
public override void G() { Console.Write("B.G"); }
}
class override_new{
static void Main() {
Son b = new Son();
Father a = b;
a.F();
b.F();
a.G();
b.G();
}
}
class Father{
public void F() { Console.Write("A.F"); }
public virtual void G() { Console.Write("A.G"); }
}
class Son: Father{
new public void F() { Console.Write("B.F"); }
public override void G() { Console.Write("B.G"); }
}
class override_new{
static void Main() {
Son b = new Son();
Father a = b;
a.F();
b.F();
a.G();
b.G();
}
}
举一反三
- 阅读以下程序class Test{static void F(){try{G();}Catch(Exception e){Console.Write(e.Message);e = new Exception(“F”);throw;}}static void G(){throw new Exception(“G”);}static void Main(){try{F();}catch(Exception e){Console.Write (e.Message);}}}以上程序运行的结果是() A: F F B: F G C: G G D: G F
- 接口Animal声明如下:public interface Animal{ void Move();}则下列抽象类的定义中, 是合法的。 A: abstract class Cat: Animal { abstract public void Move(); } B: abstract class Cat: Animal { virtual public void Move(){Console.Write(Console.Write("Move!");)} } C: abstract class Cat: Animal { public void Move(){Console.Write(Console.Write("Move!");)}; } D: abstract class Cat: Animal { public void Eat(){Console.Write(Console.Write("Eat!");)}; }
- 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"); } }
- 以下哪个方法不可以加入类Son? class Father{ public void methodOne(int i){} public void methodTwo(int i){} public static void methodTree(int i){} public static void methodFour(int i){} } class Son extends Father{…}
- 下列程序运行结果是 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"); } }