0

Why we can not extend more than one class in java? can anyone clearify this point please.

6 Answers 6

6

That's a design decision - see e.g. Why not multiple inheritance for the rationale. Short reason: MI is complex, Java doesn't want to be complex.

Sign up to request clarification or add additional context in comments.

1 Comment

also worth mentioning: most of the cases where a programmer needs MI can be resolved using an interface. +1 for simple short accurate answer.
3

James Gosling / Henry McGilton:

Multiple inheritance - and all the problems it generates - was discarded from Java. The desirable features of multiple inheritance are provided by interfaces - conceptually similar to Objective C protocols. An interface is not a definition of a class. Rather, it's a definition of a set of methods that one or more classes will implement. An important issue of interfaces is that they declare only methods and constants. Variables may not be defined in interfaces.

In other words, it eliminates the problems of ambiguity ("A" inherits "B" and "C", "B" and "C" inherits "D" - is "A" "D"?).

Instead of multiple class inheritanse, in Java you should use multiple interface inheritance. Interfaces describes behavior of object and there are no ambiguities.

Comments

1

Have a look at the Diamond Problem

Comments

0

Because java does not support multiple inheritance. Here are few articles explaining why

  1. article
  2. article

Comments

0

Long story in short,

That's why we need interfaces for. Combining interfaces together is better than an over-weight base class.

Comments

0

How about method name conflicts, for example when they same method exists in both super classes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.