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.
Review the options below to login to check your access.
Log in with your Cambridge Aspire website account to check access.
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.