程序输出题20220722

假定Base b = new Derived(); 调用执行b.methodOne()后,输出结果是什么?
public class Base
{
   public void methodOne()
   {
      System.out.print("A");
      methodTwo();
   }
 
   public void methodTwo()
   {
      System.out.print("B");
   }
}
 
public class Derived extends Base
{
   public void methodOne()
   {
      super.methodOne();
      System.out.print("C");
   }
 
   public void methodTwo()
   {
      super.methodTwo();
      System.out.print("D");
   }
}
 
只要是被子类重写的方法,不被super调用都是调用子类方法
多态中成员的特点:
  1.多态成员变量:编译运行看左边
  2.多态成员方法:编译看左边,运行看右边
 
程序输出:ABDC
posted @ 2022-07-21 23:01  三思落  阅读(24)  评论(0)    收藏  举报