8 Inheritance in Java

8.1 INTRODUCTION

The term inheritance implies that one class can inherit a part or all of its structure and behaviour from another class. Inheritance provides the idea of reusability, i.e., a code once written can be used again and again in a number of new classes. The class that does the inheriting is called a subclass of the class from which it inherits. If class B is a subclass of class A , it can also be said that class A is a super class of class B . (Sometimes the terms derived class and base class are used instead of subclass and super class) (Figure 8.1). A subclass can add to the structure and behaviour that it inherits. It can also replace or modfy inherited behaviour (though not inherited structure). The relationship ...

Get Java Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.