Public Inheritance
The most important categories of access specifier are public. Within a public derivation
- Every public member in the base class is public in the derived class
- Every protected member in the base class is protected in the derived class
- Every private member in the base class remains private in the base class
The common syntax of the public derivation is:
class base_class_name
{
......
......
};
class derived_class_name:public base_class_name
{
..................
..................
};
For instance, the following program segment demonstrates how to access every member of the base class through the derived class members:
Class baseA
{
private:
int x;
protected:
int y;
public:
};
int z;
class derivedD:public baseA
{
private:
int w;
};
A class derivedD is derived from the base class baseA and the access specifier is public. A data members of the derived class derivedD is
int x
int y;
int z;
int w;
The given table displays the access specifier of the data member of the base class in the derived class: