一. 实验目的:
二.实验内容:
输入以下代码,观察结果:
#include "twj.h"
using namespace std;
class Base {
public:
void setx(int i)
{
x = i;
}
int getx()
{
return x;
}
public:
int x;
};
class Derived :public Base {
public:
void sety(int i)
{
y = i;
}
int gety()
{
return y;
}
void show()
{
cout << "Base::x=" << x << endl;
}
public:
int y;
};
int main()
{
Derived bb;
bb.setx(16);
bb.sety(25);
bb.show();
cout << "Base::x=" << bb.x << endl;
cout << "Derived::y=" << bb.y << endl;
cout << "Base::x=" << bb.getx() << endl;
cout << "Derived::y=" << bb.gety() << endl;
return 0;
}
结果如下: