8.2 Programming with Inheritance

You do not have to die in order to pass along your inheritance.

—AD FOR AN ESTATE PLANNING SEMINAR

This section presents some basic programming techniques you need when defining or using derived classes.

Constructors in Derived Classes

A derived class, such as the class Student in Listing 8.2, has its own constructors. It does not inherit any constructors from the base class. A base class, such as Person, also has its own constructors. In the definition of a constructor for the derived class, the typical first action is to call a constructor of the base class. For example, consider defining a constructor for the class Student. One thing that needs to be initialized is the student’s name. Since the instance variable ...

Get Java: An Introduction to Problem Solving and Programming, 8th Edition 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.