Java 101 primer: Composition and inheritance

Become An Insider

Sign up now and get FREE access to hundreds of Insider articles, guides, reviews, interviews, blogs, and other premium content. Learn more.

A quick guide to the composition technique in Java programming

In "Java 101: Inheritance in Java, Part 1," you learned how to leverage inheritance for code reuse, by establishing is-a relationships between classes. This free Java 101 primer focuses on composition, a closely related programming technique that is used to establish has-a relationships instead. Whereas inheritance extends the features of one class to another, composition allows us to compose a class from another class. The distinction may seem subtle, but it will make more sense once you see it in code.

To continue reading this article register now

Join the discussion
Be the first to comment on this article. Our Commenting Policies