下面程序是关于类的继承的用法。阅读下面程序,根据程序中的注释在每一条横线处填写一个语句,使程序的功能完整,且运行程序后的输出结果为: I am parentclass! I am childclass! I am childclass! 注

admin2009-01-15  31

问题 下面程序是关于类的继承的用法。阅读下面程序,根据程序中的注释在每一条横线处填写一个语句,使程序的功能完整,且运行程序后的输出结果为:
  I am parentclass!
  I am childclass!
  I am childclass!
  注意: 请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。
  class Parent {
     void printMe()  {
      System.out.println("I am parentclass!");
      }
     }
  class Child extends Parent {
    void printMe()  {
      System.out.println("I am childclass!");
  }
   void printAll()  {
   ______________.printMe ( );    // 调用父类的方法
   ______________. printMe ( );    //调用本类的方法
    printMe ( );
  }
  }
  public class TestJieCheng {
    public static void main(String args[])  {
    ______________
    myC.printAll();
    }
  }

选项

答案super this Child myC=new Child();

解析 本题主要考查super,this关键字以及如何生成对象。解答本题的关键是熟练super,this的用法、对象的生成。在本题中, super.printMe();语句的功能是调用父类的printMe()方法,this.printMe();语句的功能是调用本类的printMe()方法,Child myC=new Child();语句的功能是生成Child类的对象myC。
转载请注明原文地址:https://jikaoti.com/ti/SJb0FFFM
0

相关试题推荐
最新回复(0)