Differentiate the properties of the following two derived classes?
(i) class X : public A{//..}
(ii) class Y : private A{//..}
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
}
Comments
Leave a comment