问答题
{{*HTML*}}给出下面程序输出结果。
#include <iostream.h>
class Base
{ private:
int Y;
public:
Base ( int y = 0 ) { Y = y; cout<<"Base ("<<y<<" ) \ n"; }
~Base() { cout<<"~Base()\n" ;}
void print() { cout<<Y<<" " ; }
};
class Derived:public Base
{private:
int Z;
public:
Derived(int y, int z):Base(y)
{Z=z;
cout<<"Derived("<<y<<", "<<z<<")\n";
}
~Derived(){cout<<"~Derived()\n"; }
void print()
{Base::print();
cout<<Z<<endl;
}
};
void main()
{Derived d(10, 20);
d.print();
}
【参考答案】
此题暂无答案,小编努力补充中……
热门
试题
问答题
{{*HTML*}}在下面程序横线处填上适当的语句,使其输出结果为0,15,15。#include <iostream.h>class base{ public:______ f() { return 0; }};class derived:public base{ public:int a,b,c;______ set(int x, int y, int z) {a =x; b =y; c =z;}int f() { return a + b + c ; }};void main(){ base b;derived d;cout<<b.f()<< , ;d.set(3,5,7);cout<<d.f()<< , ;base &p = d;cout<<p.f()<<endl;}