Introduction in Inheritance

Inheritance means inheriting the properties and behavior of something. In case of programming we use it to inherit the properties of an another class.

Inheritance


So what's exactly an Inheritance is ?

Inheritance is an important feature of object-oriented programming language that allow us to transfer the properties and behavior of a single or group of classes to a desire number of another classes.
Inheritance is used on the time of creating a new class. The new class that inherited the properties is known as "derived class" and the class that have those properties in known as "base class".

Let understand it with an simple example:
Imagine you got assignments of Physics, Computer Science & Math which you have to submit on the same day. As they all are very different from each other but the "Main Page" containing your information like name, roll, etc are same despite the "Subject Name". So you have to make three "Main Pages" for each assignment but if you have a "Xerox machine" then you can use some properties of the pre-existing page and you don't have to re-write the whole property again.
That's how inheritance works, it allows you to use the required properties from the exiting class.


Syntax:-
class Parent
{
//Body of the Parent class
};

class Child : access_specifier Parent
{
//Body of the Child class
};


Why Inheritance is used ? 

Times when the concept of Inheritance is not introduced, if we need a several number of classes which have a lot of similar properties then a programmer need to write the whole similar property in each and every class. To avoid this kind of problem and make the task easier for us the concept of inheritance has been introduced.

So some of the advantages of Inheritance are as follows:
  • Re-Usability: It allow us to use the existing code.
  • Time & Effort: It saves a lot of time and effort.
  • Simplicity: It makes the program small and easy to understand.
  • Debugging: It makes easier to debug the written program.

Types of Inheritance

There are different types of inheritance that is used in different type of purposes-

  • Single Inheritance
  • Multi-level Inheritance
  • Multiple Inheritance
  • Hybrid Inheritance
  • Hierarchical Inheritance


Also visit ----

Single Inheritance

Multiple Inheritance


Multi-level Inheritance

Hierarchical Inheritance

Hybrid Inheritance

For giving some suggestion please comment us or check our "Contact us" page. Also more update related to coding will be added in this Blog later on, so please get attached with this Blog by clicking the follow button. Thank you for your support and time...

Post a Comment

1 Comments