CSS font stacks & developer FAQs with Web standards
Site navigation below

One of hundreds of answers available with our premium content service.

Part answer, see below for more

A: You should make a judgement about which forms of inheritance are better for a particular Java application. In many cases you should use a mixture of inheritance techniques. The judgement you make will depend on the nature, scale and context of the solution you are developing.

For most relatively simple, small scale applications that can operate independently of other Java systems, class inheritance works well because of its simplicity and re-use of code. Interface inheritance tends to be used in slightly larger, broader applications, but is usually used in combination with class inheritance, not separately.

Some Java programmers argue that class inheritance should be avoided because it creates a rigid coupling and dependency between a class and its superclasses. A class can only have one superclass, so it can be difficult to extract a class from its hierarchy for use elsewhere. A more flexible alternative is to compose a class of one or more internal class fields and fulfil an interface by creating a thin “wrapper” around them.

The example below implements the standard java.util.List and an example Named interface by adapting a String and a Vector, not by inheritance. The String and the Vector are encapsulated by the host class so it is not tightly coupled.

… full answer hidden

Click for full answers

Premium members click below for full answer
Is multiple interface inheritance better than extending a class?

Premium service benefits

Your premium content subscription is a single payment that gives you:

Home · Web fonts · Font stacks · FAQs · Java · CSS · Javascript · HTML · Site manager