Login with  Log in with facebook
Hiring Manager? SIGN UP HERE
4

Does Java really support Multiple Inheritance?

Rishi Yadav
08/20/2011 at 13:10
10 Answers
1
2

This question has been asked multiple time in many exams and generally we say no as the answer. But when we say no we only think about classes in java.

I will say yes the answer of this question...Multiple iterference can be applied for interface in java.

Please give ur comments if any....

 

Puneet Agarwal
08/20/2011 at 20:43

2
2

NO java does not support multiple inheritance,,,but in case of interface it does

Mukesh Kumar
08/22/2011 at 02:42

3
1

Hi SatyaNarayana Kakitha,

Multiple inheritance makes more problems then benefits. One of the main problem with multiple inheritance is named Diamond problem and more about the problem you cen read on this Wiki page

To solve multiple inheritance problem you can do several things.

You can make interfaces and classes like in this example on Stackoverflow

Or maybe you can make inheritance like this:

class C {}

class B extends C {}

class A extends B{}

This way class A will have all public methods from class B and class C, but I don't recommend this design because classes are tight coupled.

Igor Stojanovic
08/21/2011 at 14:49

4
0

No. Java doesn't support multiple inheritance.

Igor Stojanovic
08/20/2011 at 15:23

5
0

Hi  Tadas Samerdokas,

      I didn't get exatcly why Java doesn't support multiple inheritance.Can you please give me a detailed picture on this.Or else suggest a best link to proceed on this.

 

thanks

 

Satyanarayana Kakitha
08/21/2011 at 03:57

6
0

The answer should be NO...because multiple inheritance brings many complexity but we still can acheive the same work done by multiple inheritance using interfaces coz they can be implemented in multiple inheritance fashion..

Prasanjit Biswas
08/24/2011 at 23:11

7
0

No. Java doesn't support multiple inheritance until today

Styve Uhuka
08/25/2011 at 09:36

8
0

Java does not support multiple inheritance of classes, where we have method implementations.

When we implement multiple interfaces. we are inheriting multiple types., which do not have implementations.

 

Pravin Jain
08/27/2011 at 10:44

9
0

I agree with Pravin Jain, there's no such thing as multiple inheritance in Java, and what all other posts talk about "Java can have multiple inheritance using interfaces" is incorrect, as the are talking about Multiple Implementation of interfaces.

The only thing you "inherit" from an interface is the method signature, so if you base your Specialization/Generalization process on "multiple inheritance", you'd be doing a very poor OOA&D as you'd have to implement in every new class all the methods involved in every interface you "inherit" from.

Multiple Implementation should be used to improve the software design to make the system more flexible when facing requirements changes (see Liskov substitution principle and Design by Contract).

Gerardo Robles
08/29/2011 at 11:03

10
-1

Java does not support multiple inheritance. It never will, because that is a strong violation of the OO contract.

From the theoretical perspective, this is the ONLY correct answer to this question.

However, in practice we usually have different classes that provide similar functionality and therefore interfaces are available. Interfaces are different from multiple inheritance. Let me give you an example:

If we have classes: Ship, Car, Amphibian, then in C++ we can have Amphibian as a Car and a Ship.

Assume that Ship/Car is Steerable, so they have a method 'SWheel getSteeringWheel()'. In C++'s Amphibian, we can use BOTH wheels, using Ship::getSteeringWheel() and Car::getSteeringWheel(). In Java, if we use the interface Steerable and extend either Ship or Car, we will only have access to the Ship or Cars steering wheel. That's a fundamental difference.

Stop Changing My Name!!!
08/21/2011 at 03:16

If you want to post any answer to this forum then you need to log in.
Schedule a Demo

Schedule a Demo with us

Name *
Email *
Phone *
Company *
Details