© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2024
J. FriesenLearn Java Fundamentalshttps://doi.org/10.1007/979-8-8688-0351-2_7

7. Reusing Classes via Inheritance and Composition

Jeff Friesen1  
(1)
Dauphin, MB, Canada
 

Chapter 6 introduced you to classes, which encapsulate (combine) fields (that store state), methods (that implement behaviors), and constructors (that instantiate objects). This arrangement is known as object-based programming.

Java provides an inheritance mechanism for deriving a class from another class. The idea is to reuse this other class in a more specialized manner. This arrangement is known as object-oriented programming.

Java also provides a composition mechanism for defining a class as ...

Get Learn Java Fundamentals: A Primer for Java Development and Programming 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.