Design a code for inheritance for that consider three classes namely grandfather, father and child. Each one of them has a character data type member. Each class contain a pair of constructor and destructors. The father is derived from the class grandfather. Similarly the class child is derived from class father. The class grandfather is a base class of the class father. The class father is a base class of the class child. The class child is derived from the class father. The class father is intermediate classes that act as a base class as well as derived class. Constructors are executed from the base class to the derived class and destructors are executed from the derived class to the base class.
class A
{
public:
int x;
protected:
int y;
private:
int z;
};
class B : public A
{
// x is public
// y is protected
// z is not accessible from B
};
class C : protected A
{
// x is protected
// y is protected
// z is not accessible from C
};
class D : private A // 'private' is default for classes
{
// x is private
// y is private
// z is not accessible from D
};
Comments
Leave a comment