CPP Programming
About Lesson

Once a class has been written and tested, it can be adapted by other programmers to reuse the existing class.  The mechanism of deriving a new class from an old one is called Inheritance or Derivation.  The Old class is referred to as the base class and the new one is called the derived class.

            The derived class inherits some or all of the properties from the base class.  A class can also inherit properties from more than one class or from more than one level. 

The general form of defining a derived class is:

class derived-className:visibilityMode baseClassName

{

            ….

            …

            …

};

Examples:

class ABC:private XYZ          //private derivation

{

            members of ABC;

};

class ABC: public XYZ          //public derivation

{

            members of ABC;

};

class ABC:XYZ                      //default derivation i.e. private

{

            members of ABC;

};

where colon indicates that the derived class name is derived from the base class.  The visibility mode is optional and it may take values as private or public. 

We can declare objects from both child class and parent class too.  But the objects derived from child class can access some of the members of parent class along with their own class members.  But the objects declared out of parent class can only access the members of their own class.

You cannot copy content of this page