O'Reilly logo

The class of Java by Pravin Jain

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required