Answer to Question #199298 in C++ for Dilip Kushwah

Question #199298

Differentiate the properties of the following two derived classes?

 (i) class X : public A{//..}

 (ii) class Y : private A{//..}


1
Expert's answer
2021-05-27T06:25:41-0400
Public inheritance: In case of public inheritance, it makes public members of the base class as Public in the derived class.
Private inheritance: However, in private inheritance, the public members of the base class are made as private in the derived class.

 

For Eg:

class Base {

    public:

        int x;

    private:

        int z;

};

 

class Derived1: public Base {

    // x is public

    // z is not accessible from Derived1

};

 

class Derived2: private Base {

    // x is private

    // z is not accessible from Derived2

}

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