Monday, April 19, 2010

Inheritance

As we have already discussed in the previous post, OOPS characterizes objects by their class. So, if you only know the name of the class, you can name some of the characteristics of an object, such as even if you don't know what a BMW is, if someone tells you that it belongs to the class car, you would know the basic characteristics.


Another important concept related to classes in OOP is the ability of two classes to relate to each other. This is called Inheritance. For example, sedans, roadsters, sports cars are all sub-classes of a super class called 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. A subclass may also override the methods from its parent class and give it a new definition altogether.

The inheritance in classes can go many level deep such as superclass→subclass1→subclass2→...→subclass10→...

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 superclass which is named abstract classes. Abstract classes will characterise behaviors which are common. While some aspects of this behavior may be defined, a large part of it will not be defined at all. This will allow other developers to fill in the blank spaces with unique subclasses.

2 comments:

Microgaming Slots said...

Online Article...

The information mentioned in the article are some of the top out there [...]...

latisse said...

On the net great idea