#includeusing 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(); }; int main() { ClassA number(1, 2, 3); number.x = 1;// public属性 外部可以访问 number.PublicShow();// public方法 外部可以访问 number.y = 2;//(X) protected属性 外部无法访问 number.ProtectedShow();//(X) protected方法 外部无法访问 number.z = 3;//(X) private属性 外部无法访问 number.PrivateShow();//(X) private方法 外部无法访问 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都能访问 }



