// inherit.cpp public: protected: private: // // define three classes A, B, C with variables 1, 2, 3 in // public: protected: and private: respectively // Then class D inherits public A, protected B and private C class A { public: int a1; protected: int a2; private: int a3; }; class B { public: int b1; protected: int b2; private: int b3; }; class C { public: int c1; protected: int c2; private: int c3; }; class D: public A, protected B, private C { public: int d1; // also here a1 int test(); protected: int d2; // also here a2 b1 b2 private: int d3; // also here a3 b3 c1 c2 c3 }; int D::test() { return d1 + a1 + d2 + a2 + b1 + b2 + d3; // all visible inside D // not visible a3 b3 c1 c2 c3 inside D } int main() { D object_d; // object_d has 12 values of type int in memory return object_d.d1 + object_d.a1; // only these are visible outside D // not visible object_d. a2 a3 b1 b2 b3 c1 c2 c3 d2 d3 }