Why java Don't Support Multiple interitence

Answer Posted / midhula kadiyala

If you extend more than one class JVM does n't understand
for which object it has to create object first.so ambiguios
occurs.That's y java does n't support multiple inheritance.


We can implement multiple inheritance by using interfaces.

Interface A
{
public void X();
}
class B implements A
{

public void X()
{
s.o.p("this is function x");
}
public void Y()
{
s.o.p("this is function y");
}

}

class C extends B
{
public void X(){...}
public void j(){...}

P S V M()
{

A a =new C();
a.X();
}
}

if a class wants to extend 1 or more classes define those
function definitions in one interface and in another class
provide bodies by implementing those interface.

if the class can extend the class which is implementing that
interface then u can access all functions present in that
interface.


here my interface A

i provide bodies in class B by implementing interface A

class C extend that class B

and class c is able to access all the methods present in the
interface by creating the reference of an interface with the
object of class C

(remember 1 thing to the reference of interface we can
assign object of class only if it is implementing that
interface)

here class c extends class B and again class B implements

interface A

so i can write

A a= new C();

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How are multiple inheritances done in Java?

616


What is %d in printf?

516


What is the difference between method overriding and overloading?

571


Why string is called as immutable?

522


What is a wrapper method?

531






What is native method in java?

561


Why can't we make a class private in java?

532


What is formatted output?

506


Is an integer an object?

513


How many times finalize method will be invoked? Who invokes finalize() method in java?

570


How to set the permissions to a file in java?

533


how to create constants in java?

599


Differentiate storage classes on the basis of their scope?

668


What is currentthread()?

570


What is use of arraylist in java?

579