Inheritance vs Interface
The following text is from Roedy Green’s Java Glossary on the Web.
On the surface, interfaces and abstract classes seem to provide almost the same capability. How do you decide which to use?
When to Use Interfaces
An interface allows somebody to start from scratch to implement your interface or implement your interface in some other code whose original or primary purpose was quite different from your interface. To them, your interface is only incidental, something that they have to add on to their code to be able to use your package.
When to Use Abstract Classes
An abstract class, in contrast, provides more structure. It usually defines some default implementations and provides some tools useful for a full implementation. The catch is, code using it must use your class as the base. That may be highly inconvenient if the other programmers wanting to use your package have already developed their own class hierarchy independently.
Explain these ideas in your own words. Give an example of an application where an interface is more natural and one where inheritance of an abstract class is more natural.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.