(Not So) Stupid Questions
Inheritance vs. Interfaces
Editor's note: Sometimes, the most interesting discussions begin when someone says, "This may be a stupid question, but ...." If the person asking the question has taken the time to think about the problem before asking, the question is often not stupid at all. Uncertainty points out an ambiguity in specs, holes in docs, or a search for how more experienced programmers might address a particular problem. From time to time, we will publish one of the "(Not So) Stupid Questions" we receive and invite our readers to answer the question in the feedback section.
Remember that new people are joining the Java community all the time and may be looking for help from those with more experience. Also, those who began with Java as their first language can benefit from those coming to the community with experience in other languages. As always, answer the questions with kindness. You are also welcome to submit your questions to
This may be a stupid question, but ... "When should I implement an interface, over inheriting from a parent class? "
I know this is done to avoid multiple inheritance, but I also know that you can write an interface and implement it instead of using inheritance. This arrangement allows you to implement behavior defined by many different interfaces, but stay out of the trouble that would ensue if, for example, you could inherit from two concrete classes and both had a method with the same name and same parameters.
An abstract class is kind of like an interface, in that it's meant to be extended, but your class can only inherit from one class, abstract or not. That seems different than implementing an interface anyway, since the abstract class can provide method implementations for subclasses to inherit, something interfaces can't do.
This brings me to two questions:
1. Should we completely avoid inheritance, and only use interfaces? and
2. If so, how will analysts know whether to continue to construct analysis class models using inheritance?
"(Not So) Stupid Questions" is where we feature the questions you want to ask, but aren't sure how.