INHERITANCE

INHERITANCE – Introduction of Inheritance, Types

Introduction –

Well now a day’s computer has been a tremendous influential topic to speak about but the most common interest that is being prevailed in the computer is coding. Starting from games to all the graphical works, the designs to presentations coding always makes our work easier and more innovative. Earlier during the start of the computer network MS word was the most wanted criteria of a user but now with the passage of time, we find interest growing in innovations and technical works which involve a lot of coding and making our task simpler, efficient for the computer to understand and increases our time complexity.

INHERITANCE

We have already come across many words that might be new here, for example, time complexity. Well, the time complexity is nothing but the time required by the computer to complete the task. The best performance of a computer is considered when both the time and space complexity is less. Such a computer is considered to be the most user-friendly and easy to handle. Now when we had started writing the word in the English language, we did not directly start from making sentences.

We first came across letter then word making and slowly and steadily we came to know about the make sentences similarly before knowing about the further details that a user would be enlightened to talk about let us start with the beginning of the topic that we have started with. Inheritance is basically the characteristic which a class has in order to derive the behavior and properties of another class. It is one of the most essential and basic concepts of OOP.

OOP or object-oriented programming is a software design where we can define different data types, data structures, functions that can be applied to a programming language. There has been an evolution of a number of programming languages like java, c, C++, python and many more. All of the programming languages are either classified in accordance with high-level language or low-level language but the concept of OOP always remains the same. These are the basic properties that are required for the proper functioning of program code or for knowing more.

INHERITANCE

When we come to the inheritance and class a and objects, we also need to know them before we can successfully apply the idea of inheritance. Inheritance is custom logic that adds to the existing framework and maps our domain model to a database. Before we further get into the details of inheritance let us know what are the access modifiers and encapsulation.

Access modifiers define what a class can access an attribute or a method whereas encapsulation is the process of hiding the data from the outside world. We got the necessity to learn about these 2 as the data which is protected through encapsulation is transferred through the access modifiers in case of inheritance to the other class. They affect the entities and attributes that we can access within an inheritance hierarchy. Now the access to a class can be of 3 types public, private and protected.

The subclass can access the attributes of both public and protected entities of another class but if the subclass and superclass belong to the same class then they also have access to the private entities. Inheritance not only adds all the public and protected methods of our subclass to the superclasses but it also provides us a way to replace the implemented data. Now one of the common concepts that get confused with inheritance is subtyping. In some languages, they both are highly confused while in general studies subtyping establishes a relationship between the data whereas in inheritance only the inherited properties matter.

INHERITANCE

Just like in English we say inheritance of the wealth from the ancestors to their children similarly the subclass which are the children of the superclasses inherits the properties, entities, and behavior of the other classes. It is absolutely in contrast to the object composition. In object composition, we can see the objects contain the other objects. There are different types of inheritance that we know about they are:

Single inheritance
Multiple inheritances
Multilevel inheritance
Hierarchical inheritance
Hybrid inheritance

In the 1st case of single inheritance, the subclasses inherit the features of 1 superclass. A class which acquires the properties of another class. In the 2nd case of multiple inheritances, we get to know that one class can have more than 1 superclass and inherits the attributes and behaviors from all of its parent classes.

In the 3rd case, we come to know about the multilevel inheritance which highlights the subclass derived from another subclass. It is certainly not very uncommon that a class is derived from another derived class and this is called multilevel inheritance. In the 4th one that 1 class serves as the base class for more than 1 subclass. And finally, a mix of 2 or more of the mentioned types of inheritance is called the hybrid inheritance.

(image source google search)

Hi there! Welcome to Information Mania a website where you can find the latest and interesting blogs and articles hope you will like it and support us. As we are growing and learning new things every day and also trying to share that with all of you in our post and blogs. I love to hear your suggestions and ideas in the comments! contact us: [email protected]

Leave a Reply

Your email address will not be published.