下列程序的输出结果是______。 #include<iostream.h> class base { int x,y; public: base(int i,int j){x=i;y=j;}

admin2013-02-27  18

问题 下列程序的输出结果是______。
   #include<iostream.h>
   class base
   {
       int x,y;
   public:
       base(int i,int j){x=i;y=j;}
       virtual int add( ){return x+y;}
   };
   class three:public base
   {
       int z;
   public:
       three(int i,int j,int k):base(i,j){z=k;)
       int add( ){return(base::add( )+z);}
   };
   void main( )
   {
       three*q=new three(10,20,30);
       cout<<q->add( )<<endl;
   }

选项

答案60

解析 本题考察继承中子类对父类的继承方式,注意子类的add成员函数,它直接使用了父类的成员函数进行运算。
转载请注明原文地址:https://kaotiyun.com/show/szNp777K
0

最新回复(0)