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 4: Inheritance

Chapter 4: Inheritance

pp. 207-286

Authors

, Indian Institute of Technology, Kharagpur, , Indian Institute of Technology, Kharagpur
  • Add bookmark
  • Cite
  • Share

Extract

Java developer aims at Java programming suitable for fast, large, complex, and safety-critical software development. One important requirement towards this is to code reusability. Code reusability helps a programmer to use code which is already developed by someone else. For this reason, Java developer introduces one of the most magnificent object-oriented programming features called inheritance. This feature allows a programmer to access fields and methods of an existing class to their new class under development. Inheritance thus facilitates inheriting some of the characteristics in a child class from its parent class. It is just like a ladder from the child class to the parent class. In addition to code sharing, access privilege is also taken into consideration in the inheritance mechanism. This enables protection of data and code from unauthorized access.

Introduction

Why inheritance? Class is the basic element of any software in object-oriented system design approach. In the last chapter, you have learned about how to write classes in Java programs. In software development, a software is under constant updation, for example, extension (from one version to the next or from one release to another, etc.), or modification (correction of some faults or to make it compatible with new technology, hardware, etc.). The requirement is that all the development should take place without disturbing the existing system and, of course, with minimum effort and time.

Your learning Inheritance in Java is a clever mechanism to support these requirements. It allows an efficient and secure way to share code, modify it, and reuse it. With the help of inheritance, you will learn how to extend a given class and thus access its fields and methods. You will also learn how to hide some fields and methods from a parent class to the extended class.

Concept of Inheritance

Basic concept The inheritance concept is related to taxonomy or classification. For example, Figure 4.1 shows taxonomy (in partial form) of animals. It looks like a tree (this is why it is also called and inheritance tree). This tree bears the information that lion and hyena, for example, have some common characteristics. In addition, they have their own characteristics.

About the book

Access options

Review the options below to login to check your access.

Purchase options

eTextbook
US$99.99
Paperback
US$99.99

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