Answer to Question #178326 in C++ for Avni

Question #178326

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.


1
Expert's answer
2021-04-05T20:39:15-0400
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
};

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS