Chapter 6. Inheritance

We explored the first OOP principle—encapsulation—in the preceding chapter, by way of classes and objects. The second OOP principle is known as inheritance. Java divides inheritance into implementation inheritance (by extending classes) and interface inheritance (by extending and implementing interfaces). This chapter begins its exploration of inheritance by introducing that concept and by focusing on implementation inheritance. A detailed look at the root of all Java classes follows. Then, interfaces and interface inheritance are explored. This chapter concludes its exploration of inheritance by discussing composition and its relationship to inheritance.

What Is Inheritance?

We live in a world of relationships. For example, ...

Get Java™ 2 by Example, Second 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.