Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Why java Don't Support Multiple interitence

Answers were Sorted based on User's Feedback



Why java Don't Support Multiple interitence..

Answer / g ch vishnu vardhan reddy

Multiple Inheritance is not supported by java in order to
avoid ambiguity between variables of different classes and
to rudece memory overloading.

Is This Answer Correct ?    42 Yes 1 No

Why java Don't Support Multiple interitence..

Answer / bhaskar reddy

There is a big reason behind that(java does not support
multiple inheritance). Please go through the following
example.

1. Assume that java is supporting multiple inheritance

class A {

void m1() {
// implement method
}
}

class B {
void m1() {
// implement method
}
}
//As for the assumption (1) the following code will compile

class C extends A,B {

public static void main( String s[]) {

C c = new C();
c.m1();
}
}

Note : In main method i am calling c.m1() method In this
situation which super class m1 method has to call (from A
or B) JVM will confuse.

So our assumtion(1) is wrong .

This is the reason why java does not support multple
inheritance through classes.

Note : This same cocept is applicable for classes.

Is This Answer Correct ?    29 Yes 4 No

Why java Don't Support Multiple interitence..

Answer / 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

Why java Don't Support Multiple interitence..

Answer / sanjeev

Why cant we face same ambiguity when we declare variables?
interface A{
int i = 10;
}
interface B{
int i = 20;
}
Class C implement A, B{
what is the value of C.i?
}

Is This Answer Correct ?    0 Yes 1 No

Why java Don't Support Multiple interitence..

Answer / srinu

Java Does not support Multiple inhertiance through class
because ambiguity between variables of different classes
and to rudece memory overloading.and another reason java
extended only one class at time

java support Multiple inhertiance through interfaces.because
java class implements any number of interface at time

Is This Answer Correct ?    0 Yes 2 No

Why java Don't Support Multiple interitence..

Answer / kiranksj

ya java don't support multiple interitence but by achieving
it the interface are came

Is This Answer Correct ?    2 Yes 6 No

Why java Don't Support Multiple interitence..

Answer / sid

The famous "diamond shaped problem " is the reason behind NOT using multiple inheritance in java.
check out this link for full details
http://en.wikipedia.org/wiki/Diamond_problem

Is This Answer Correct ?    0 Yes 4 No

Why java Don't Support Multiple interitence..

Answer / samir rana

java support multiple inheritance not through the use of
class, but through the implementation of interface we can
achieve multiple inheritance.

By using interface we can implement multiple interfaces for
a class which can solve the problem of our multiple inheritance.

Is This Answer Correct ?    0 Yes 4 No

Post New Answer

More Core Java Interview Questions

Why Wait and notify are kept in Object class although they are used only with Thread Class

2 Answers   Global Logic, Saksoft,


Addition to previous section relative word 5th one was Putrid ans: rotten, also there was prob. in 1st section on bucket weight ans:10kg, also there was a prob. on train speed to find bridge length ans:800 mtrs.

0 Answers   V2 Solutions,


Explain class A{} class B{} class C{} all the three classes are saved in a single file name, what the name should i provide to the file ,in what file name should i run the program? Ple Explain

9 Answers   DNS, Infosys, TCS,


What is the difference between I ++ and ++ I in java?

0 Answers  


"we cannot create an object of interface but we can create a variable of it".diacuss the statement with the help of an example.

2 Answers  


Which collections are thread safe in java?

0 Answers  


What is the use of System class?

0 Answers  


what is the purpose of class "Object" which is base class for all classes?

3 Answers  


What are keyboard events?

0 Answers  


Write a program to find maximum and minimum number in array?

0 Answers  


What is nan in java?

0 Answers  


What type of variable is error flag?

0 Answers  


Categories