Inheritance in Object Oriented Programming:

Inheritance is the process by which objects can acquire the properties of objects of other class. In OOP, inheritance provides reusability, like, adding additional features to an existing class without modifying it. This is achieved by deriving a new class from the existing one. The new class will have combined features of both the classes. 

Types of Inheritance:
1. Single inheritance
2. Multiple inheritances
3. Multilevel inheritance
4. Hierarchical inheritance
5. Hybrid Inheritance

There are three types of class inheritance: public, private and protected The protected access specifier is similar to private. Its only difference occurs in fact with inheritance. When a class inherits from another one, the members of the derived class can access the protected members inherited from the base class, but not its private members.

Difference between public, private and protected:

1. A member (either data member or member function) declared in a private section of a class can only be accessed by member functions and friends of that class
2. A member (either data member or member function) declared in a protected section of a class can only be accessed by member functions and friends of that class, and by member functions and friends of derived classes
3. A member (either data member or member function) declared in a public section of a class can be accessed by anyone.





Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: