Does Java support multiple Inheritance?

Answers were Sorted based on User's Feedback



Does Java support multiple Inheritance?..

Answer / debapriya patra

Java does not support multiple inheritance.Why?

If anybody ask u why java does not support multiple
inveritance then answer is:"Whenever we create an instance
of a child class and we extend more then one class like
C++, then if these two classes contain same variable then
which will print if we try to print the variable."

Example:
class a
{
int i = 10;
}
class b
{
int i = 10;
}

class c extends a,b
{
public static void main(String[] args)
{
c c1 = new c();
System.out.printn(c1.i);//Here an ambiguous situation
will occur
}
}

Is This Answer Correct ?    29 Yes 14 No

Does Java support multiple Inheritance?..

Answer / ujas doshi

No...Actually java does not support multiple inheritance.
You can say bcoz of reason mentioned by debapriya.

But if you want a class to be inherited from 2 classes you
can use a concept in java called interfaces..

class C extends A, extends B ---wrong, error, only one
class can be inherited

class C implements A, implements B ---fine, here A and B
are not classes but they are interfaces.

Now what are interfaces?
interfaces are similar to classes except a few things
1)Interfaces must contain static methods only

Is This Answer Correct ?    17 Yes 10 No

Does Java support multiple Inheritance?..

Answer / tarun

I want to make sure that The answer provided by Tewodros
Tesema is an example of multilevel inheritence not multiple
inheritence which is supporte by java and it is true.
But Java does not supports multiple inheritence. In the case
of Interface we can inherit multiple interfaces by
sepertaing them with comm(,). But a class can inherit a
single class at a time.

Is This Answer Correct ?    6 Yes 0 No

Does Java support multiple Inheritance?..

Answer / ujas

for any more doubts mail me to ujas.doshi@atosorigin.com

Is This Answer Correct ?    3 Yes 2 No

Does Java support multiple Inheritance?..

Answer / gyana

No actually java doesn't support multiple inheritance.But
we can use this by using Interface in java.

for example Class x,implements y, implements z.

here x is the main class and the two interface y and z
implements it in its program.y and z are two interfaces not
classes.

Is This Answer Correct ?    3 Yes 2 No

Does Java support multiple Inheritance?..

Answer / janardhan

In java single inheritance is possible, not multiple
inferitance.

in java one class extends only one class not more than one.
But in java one class implements multiple interfaces. some
time we will call multiple inheritance possible by
interfaces.


jana

Is This Answer Correct ?    2 Yes 1 No

Does Java support multiple Inheritance?..

Answer / ramakrishna

JAVA omits many rarely used, poorly understood,
confusing features of C++ that in our experience bring more
grief than benefit. This primarily consists of operator
overloading (although it does have method overloading),
multiple inheritance, and extensive automatic coercions.

Who better than Dr. James Gosling is qualified to make a
comment on this. This paragraph gives us an overview and he
touches this topic of not supporting multiple-inheritance.
Java does not support multiple inheritance

First lets nail this point. This itself is a point of
discussion, whether java supports multiple inheritance or
not. Some say, it supports using interface. No. There is no
support for multiple inheritance in java. If you do not
believe my words, read the above paragraph again and those
are words of the father of Java.

This story of supporting multiple inheritance using
interface is what we developers cooked up. Interface gives
flexibility than concrete classes and we have option to
implement multiple interface using single class. This is by
agreement we are adhering to two blueprints to create a class.

This is trying to get closer to multiple inheritance. What
we do is implement multiple interface, here we are not
extending (inheriting) anything. The implementing class is
the one that is going to add the properties and behavior. It
is not getting the implementation free from the parent
classes. I would simply say, there is no support for
multiple inheritance in java.

Is This Answer Correct ?    1 Yes 0 No

Does Java support multiple Inheritance?..

Answer / sadikhasan,meta

Java does not support multiple inheritance because it
creates a dimond problem.

if we want to implement multiple inheritance in java then we
use interfaces which support multiple inheritance.

e.g.
interface B
{
}
interface C
{
}
class A implements B,C
{
}

Is This Answer Correct ?    2 Yes 2 No

Does Java support multiple Inheritance?..

Answer / divyesh chauhan

yes java do not support multiple inheritance but we can achieve multiple inheritance using concept of interface implementation in class
for e:g
interface my
{
public void show();
}
interface my1 extends my
{
void disp();
}
class child implements my1
{
public void show()
{
System.out.println("hello java");
}
public void disp()
{
System.out.println("hello disp");
}
public static void main(String...a)
{
my m1=new child();
m1.disp();
m1.show();
}
}

Is This Answer Correct ?    0 Yes 0 No

Does Java support multiple Inheritance?..

Answer / ershad

Bcoz of DIAMOND PROBLEM (this term we hav 2
used )..diamond problem is one which does not supports
Multiple inheritance

Is This Answer Correct ?    3 Yes 5 No

Post New Answer

More Core Java Interview Questions

what is object-oriented programming in java?

0 Answers   Reliance,


What is the difference between array list and vector in java?

0 Answers  


Is 0 a real number?

0 Answers  


What does method mean?

0 Answers  


What is the use of StringTokenizer class?

0 Answers   Hexaware, Virtusa,






I have a String s = java; What is the output when I say s.replaceAll('j', 'k'); Also what is the value of s after replacing?

8 Answers   KPIT,


Why we need to serialize the object

11 Answers   CTS, Geometric Software,


difference between vectorlist and hash

1 Answers   TCS,


What is finally block?

0 Answers  


hr interview how many minutes asking question

0 Answers  


I have multiple constructors defined in a class. Is it possible to call a constructor from another constructor’s body?

0 Answers  


How to create a thread in java?

0 Answers  


Categories