高等继续教育 / 面向对象程序设计
正确率:推荐%
题型描述: 简答题
给出下面程序输出结果。
#include <iostream>
using namespace std;
class Base {
private: int Y;
public:
Base(int y=0) {Y=y;cout<<y-1<<' ';}
~Base() {cout<<0<<' ';}
void print() {cout <<Y<<' ';} };
class Derived:public Base
{private: int Z;
public:
Derived (int y, int z):Base(y)
{ Z=z;
cout<<y-2<<' '<<z+3<<' '; }
~Derived() {cout<<1<<' ';}
void print() {Base::print(); cout<<Z<<' '; }
};
int main()
{
Derived d(50,60);
d.print();
return 0;
}
参考答案:
佳题速递: