c++特性之一-----继承
时间:2010-11-12 来源:my blog
#include <iostream.h>
class Animal
{
public:
void eat()
{
cout<<"animal eat"<<endl;
}
protected:
void sleep()
{
cout<<"animal sleep"<<endl;
}
public:
void breathe()
{
cout<<"animal breathe"<<endl;
}
};
class Fish:public Animal
{
public:
void test()
{
sleep();
}
};
void main()
{
Animal an;
Fish fh;
fh.test();//子类可以通过内部成员函数来访问父类的保护成员
fh.sleep();//子类不能直接访问父类的保护成员。
}
3. 继承中私有成员无论怎样都不能被子类访问!
相关阅读 更多 +










