5. Interfaces and Inheritance

Chapter Contents

Interfaces

Inheritance

You saw an example of implementing an interface in Chapter 4. You can read more about interfaces in the first section of this chapter: what they are for, why you might want to write one, and how to write one. The second section of this chapter describes the way in which you can derive one class from another—that is, how a subclass can inherit fields and methods from a superclass. You will learn that all classes are derived from the Object class and also learn how to modify the methods that a subclass inherits from a superclass. This section also covers interface-like abstract classes. Each section ends with questions and exercises to test your understanding.

Interfaces

Get The Java® Tutorial: A Short Course on the Basics, Fifth 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.