Skip to main content Accessibility help
Internet Explorer 11 is being discontinued by Microsoft in August 2021. If you have difficulties viewing the site on Internet Explorer 11 we recommend using a different browser such as Microsoft Edge, Google Chrome, Apple Safari or Mozilla Firefox.

Chapter 14: Inheritance

Chapter 14: Inheritance

pp. 770-880

Authors

, Vidyalankar Institute of Technology
  • Add bookmark
  • Cite
  • Share

Summary

Overview

Inheritance is a relationship between classes wherein one class is derived from another class. The derived class is called child class, and the class from which it is derived is called parent class. Inheritance is also called as parent–child relationship between classes such that child class gives a specialized implementation of parent class. Reusability of the code is the key principle of inheritance because the properties defined in the parent class are borrowed by the child class. Inheritance is one of the most important features of object oriented programming, wherein the classes are organized in a hierarchical form. The class at the top of hierarchy is called parent class, whereas the class at the bottom of the hierarchy is called child class. Advantage of inheritance is that the members (variables and functions) defined by the parent class are also made available into the child class. This saves the programmers efforts to redevelop logic in child class, which is already implemented in parent class. Along with the properties defined in parent class, the child class can also have additional properties of its own as shown in the Figure 14.1. Hence the parent class is also called Base class/Super class/Generalized class and the child class is also called Derived class/Sub class/Specialized class.

As seen from the Figure 14.1, the member1 and member2 are defined in the parent class, which are available by default, in the child class. Also, child class can define additional members such as member3 and member4. This means that if you create an object of parent class, it will contain only two members: member1 and member2; whereas, if you create an object of child class, it will contain four members: member1, member2, member3, and member4. Therefore, a parent class should define the common properties that are required by all the child classes, whereas each of child class should define the specialized properties applicable only for that child.

As an example, let's assume that we need to store data about students and professors in a particular institute in computer memory. The requirement is that for every person(a student or a professor)we need to store name, date of birth, and gender.

About the book

Access options

Review the options below to login to check your access.

Purchase options

eTextbook
US$110.00
Paperback
US$110.00

Have an access code?

To redeem an access code, please log in with your personal login.

If you believe you should have access to this content, please contact your institutional librarian or consult our FAQ page for further information about accessing our content.

Also available to purchase from these educational ebook suppliers