CHAPTER 6
Inheritance and Sub-classing
In Chapter 5, we have seen how to define a class and the various kinds of members that can be defined in a class. Let us now look at how we can create a sub-class of a given class in Java. A sub-class always inherits the functionality of the super-class and can always add more functionality. A sub-class is created when it can be represented by an ‘is a’ relation. There are many examples of super-class and sub-class relationships in the real world, e.g. Car is a sub-class of Vehicle. This is so since Car is a Vehicle. The two types Vehicle and Car are related using the ‘is a’ relationship. Let us look at how to define a sub-class in Java.
6.1 DEFINING SUB-CLASSES
For the purpose of understanding the sub-classing ...
Get The class of Java 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.