The Inheritance Concept In OOPs
In object oriented programming, objects will be characterised by classes. It is possible to learn a lot about an object based on the class it belongs to. Even if you are not familiar with the name Maybach, If I told you it is a car, you would immediately know that it has four wheels, an engine, and doors. Objected oriented programming takes this concept to a whole new level.
It permits classes to be defined in relation to other classes. For example, sedans, sports cars, and roadsters are all types of cars. In the object oriented language, sports cars, sedans, and roadsters are subclasses of the class cars.
The class cars is a "superclass" of sedans, roadsters, and sports cars. Every subclass will inherit a state from the superclass. The various types of cars such as sedans and roadsters will share certain behaviors such as braking. Despite this, subclasses are not restricted to the behaviors and states that they have taken from their superclass. A subclass can combine methods and variables with the traits they have inherited from their superclass. For example, while a sedan may have four dours, sports cars will generally have two. It is also possible for subclasses to override any methods that they have inherited, and they can create unique implementations for these methods.
As an example of this, you can "override" certain traits within a car to allow it to do different things. It is also possible to use more than just one level of inheritance. An inheritance structure can be generated which can be as deep as you want it to be. This inheritance structure is called a class hierarchy. The variables and methods can extend through the levels of the class hierarchy. In most cases, a hierarchy that is deep tends to have behaviors which are distinct. However, there are a number of important things you should know about a class hierarchy. It should always define what the classes are instead of how they are used.
For example, if you are implementing a class for muscle cars, it may be helpful to set it up as a subclass of the class cars. The reason for this is because muscle cars are a subgroup of the class cars that have large amounts of power. At the same time, because a muscle car is a subgroup of the class cars, you would not want to connect them together directly. If you do this, you may confuse those that use your program. They may become confused because the muscle car could have methods that are not necessary, and this could make it difficult to handle the application.
The object class should be at the zenith of the class hierarchy. Every class should descend from it in a direct or indirect manner. The variable of an object type can retain a reference for any object, and an example of this would be a class. For example, the object could define behaviors that may be attributed to the objects that are processed by the Java Virtual Machine. There are a number of power advantages to the concept of inheritance. Subclasses can generate distinct behaviors which are based on the common attributes that are present in their superclass. Because of inheritance, it is possible for programmers to use the same code many times over.
In addition to this, programmers can generate superclasses which are named abstract classes. Abstract classes will characterise behaviors which are common. While some aspects of this behavior may be defined, a large portion of it will not be defined at all.
This will allow other developers to fill in the blank spaces with unique subclasses. As you can see, an inheritance is extremely important. It shows how subclasses are connect to their superclasses, and it can also allow you to understand which traits have been passed from the superclass to its subclasses. It is one of the most powerful features of object oriented programming. It is used in a number of popular programming languages such as Java. It is features like this that makes OOP a powerful tool that many programmers use to create important programs. However, it is just one of the few concepts that you must understand if you wish to use this programming paradigm.