What is Inheritance ? How is a Class Inherited in C++ ?

October 28, 2007 · Filed Under C++ Questions, Placement Questions 



Don't want to miss a single bit? Subscribe By Email for Daily Jobs

Enter your email address :

All the latest from JobsAdda on Jobsadda.com delivered to your mailbox everyday.

Inheritance is one of the most important principles of object oriented language. Using inheritance one can create a class that can have traits common to a set of related items.

This class is then inherited by other classes each adding things are specific to them. The class that is inherited is called the base class and the class that inherits from it is called as the derived class. When a class inherits a base class, then all the members of the base class become members of the derived class.

E.g. class derived-class-name:: access base-class-name
{
//body of class
};

The access of the members in the base class by derived class depends on the access parameter. The access specifier must either be private, public or protected. If one doesn’t provide an access specifier then it is taken as private by default.

When access specifier is private then these members remain private to base class and the derived class cannot access them. When access specifier is public then all the public members of a base class become public members of the derived class and all the protected members of the base class become protected in the derived class. On using a protected access specifier all public and protected members of the base class become protected members of the derived class.

Related Articles


Get Latest JobsAdda.com Jobs, news & updates  via Email