Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Unit Testing in Java Why Test? Composition vs. Inheritance

Filipp Uvarov
Filipp Uvarov
767 Points

Composition vs Inheritance. The first question has wrong right answer

The statement goes like this: When you use the inheritance model of code re-use, you must implement ALL public methods provided by the parent class.

For some reason the right answer for this question is TRUE. This is not how Java works, you do not have to implement ALL public methods of a parent class unless parent class is an interface or an abstract class ALL of which methods are abstract.

1 Answer

Ignazio Calo
PLUS
Ignazio Calo
Courses Plus Student 1,819 Points

I din't take this class, but from your explanation I would say that yes, you're right a JAVA subclass doesn't need to implement method of a superclass.

The only thing that comes to my mind, considering that we are talking about code re-use, is that maybe the author doesn't mean "literarily" implement but he's talking about the fact that in a subclass you "cannot remove" a method implemented in a superclass. Of course you can override with an empty implementation, but there is no way that your subclass can "do not implement". a method defined into a superclass.