Inheritance – Feature of Object Oriented Programming (OOP)

Download our Android App from Google Play Store and start reading Reference Notes Offline.

inheritanceInheritance – Characteristics of Object Oriented Programming (OOP)
Object Oriented Programming(OOP)
Third Semester | Second year
BSc.CSIT | Tribhuvan University (TU)

Inheritance
Inheritance is a mechanism by virtue of which the classes inherit the attributes and methods of some other class(s). In a sense, we can say, inheritance is a way to reuse the code of some existing or already defined classes. The classes, in this case, are said to have ‘a kind of’ and ‘is a’ relationship with the other classes. Using this property of OOP, one class can extend other classes by including additional methods and/or attributes (variable). The original class is called the ‘superclass’ of the extending class and extended class is called the ‘subclass’ of the class that is being extended. The subclass is sometimes known with the name of ‘derived’ class and the superclass with the name of ‘base’ class. The derived or subclasses can further be used to have their own derived subclasses. This kind of a relationship of classes through inheritance gives rise to an inheritance hierarchy of the classes.

As an example, if you take ‘car’ as a superclass, then you can treat sedan, sports car, roadster as its subclasses. All or some of these subclass cars have some common attributes (structure) and methods (behaviour). But the structure and behaviour of these subclass cars is not restricted to those of the superclass ‘car’. A subclass car can contain methods and attributes in addition to those inherited from the superclass ‘car’ e.g. a sports car will generally have only two doors whereas a sedan will have four. The subclasses can also contain methods that override the methods they have inherited to have unique implementation of these methods. Another example of inheritance can be that of a ‘geometric figure’ as a superclass and a ‘circle’ and a ‘triangle’ as its subclass as shown in figure below;

Inheritance among classes

Fig: Inheritance among classes

Various categories of Inheritance which are often used in OOP are single level, multi-level, multiple inheritance etc.

(Visited 139 times, 1 visits today)

Posted By : Digvijay | Comment RSS | Category : Third Semester
Tag : ,

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

Wordpress DMCA
Community | Toolbar | Android App | Founder/Developer : Hari Prasad Chaudhary | CSIT Portal Manager : Digvijay Chaudhary