#include
using namespace std;
class ClassA
{
public:
int x;
void PublicShow();
ClassA(int x = 1, int y = 2, int z = 3);
~ClassA();
protected:
int y;
void ProtectedShow();
private:
int z;
void PrivateShow();
};
class ClassB:public ClassA
{
public:
int a;
void PublicShow();
ClassB(int a = 3, int b = 4, int c = 5, int x = 1, int y = 2, int z = 3);
~ClassB();
protected:
int b;
void ProtectedShow();
private:
int c;
void PrivateShow();
};
int main()
{
ClassB number(4, 5, 6, 1, 2, 3);
number.PublicShow();
number.PublicShow();
return 0;
}
ClassA::ClassA(int x, int y, int z)
{
this->x = x;
this->y = y;
this->z = z;
}
ClassA::~ClassA()
{
}
void ClassA::PublicShow()
{
cout << x << "+" << y << "+" << z << endl;
//Public中方法,x y z都能访问
}
void ClassA::ProtectedShow()
{
cout << x << "+" << y << "+" << z << endl;
//Protected中方法,x y z都能访问
}
void ClassA::PrivateShow()
{
cout << x << "+" << y << "+" << z << endl;
//Private中方法,x y z都能访问
}
ClassB::ClassB(int a, int b, int c,int x,int y,int z):ClassA(x, y, z)
{
this->a = a;
this->b = b;
this->c = c;
}
ClassB::~ClassB()
{
}
void ClassB::PublicShow()
{
cout << x << "+" << y << "+" << a << "+" << b << "+" << c << endl;
//cout << x << "+" << y << "+" << z << endl;
//ClassB Public方法中,z无法访问
}
void ClassB::ProtectedShow()
{
cout << x << "+" << y << "+" << a << "+" << b << "+" << c << endl;
//cout << x << "+" << y << "+" << z << endl;
//ClassB Protected方法中,z无法访问
}
void ClassB::PrivateShow()
{
cout << x << "+" << y << "+" << a << "+" << b << "+" << c << endl;
//cout << x << "+" << y << "+" << z << endl;
//ClassB Private方法中,z无法访问
}
private:一个类固有属性,一个类区别于另一个类,就靠它,不与外界直接交流
protected:一种对子类完全开放的属性,不与外界直接交流
public:一个类与外界交流的唯一出入口