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 does java doesnot support multiple inheritance?

Answers were Sorted based on User's Feedback



Why does java doesnot support multiple inheritance?..

Answer / rathnakar

--> Java follows Super Class Object and Sub Class reference
at runtime to excute inherited and overridden methods.

--> Java doesnot support multiple inheritence by using
classes.becoz java compiler gets ambiguity if one method
is defined in many child classes. this happens due to
above reason

--> so execution fails . but it can be achieved using
interfaces. becoz it method over riding and every child
class is identified uniquely w.rt to interface.

Is This Answer Correct ?    8 Yes 0 No

Why does java doesnot support multiple inheritance?..

Answer / balu

multiple inheritance is not available in java for the following reasons
1.it leads to confusion for a java program
2.the programmer can achieve multiple inheritance by using interfaces
3.and also we can achieve it by repeatdly using single inheritance.

Is This Answer Correct ?    7 Yes 0 No

Why does java doesnot support multiple inheritance?..

Answer / msraju

Every class in java must have only one root class (i.e
Object class) directly or indirectly.
If Class C extends Class A and Class B(this approach is not
supported in java ),here Class A will one root Object
class,similarly Class B will have Another root class.i.e
Here Class C is having two root classes....For this reason
java not supporting Multiple inheritance with respective
Objacts.
Every objects need some common functionalities which are
available in Object class.

Is This Answer Correct ?    2 Yes 0 No

Why does java doesnot support multiple inheritance?..

Answer / deep

Multiple inheritance Oops i think diamond problem..


class A {
public void x() {
System.out.println("Hello");
}

class B extends A {
public void x() {
System.out.println("Hello");
}

class C extends A {
public void x() {
System.out.println("Hello");
}

// Main class
class AB extends B,C // Remember this is not possible in java, a class can extend only one class in java..
{
public static void main(String args[]) {

AB a = new AB();
a.x(); // compiler gets confused whom should i call.. which methods should i invoke since both methods has same name i.e public void x(), complier get scared and raise an error of ambiguity
}
}

To avoid this type of situation, designers of java decided that a class can extends only one class so there would be no ambiguity of methods.. and to over come this issue they added interface..

class can implements n number of interface but can extend only one class.. a interface can extends n number of interface..

Variables declared inside interface are by default,, static and final.. and methods are abstract i.e unimplemented methods, that doesn't have body.. methods of interface are by default abstract and public..

you can make interface public or depends on your requirement.. if you want a interface to access outside of another package better make it public cause non public classes are confined within same package..

Is This Answer Correct ?    1 Yes 0 No

Why does java doesnot support multiple inheritance?..

Answer / rana.ankur

Suppose consider a method funX() which is in class Z.

Suppose a programmer A inherited the class Z to class X and
overrided the funX().So this class will have the new
implementation of funX(). ie class X extend Z
Suppose a programmer D inherited the class Z to class Y and
overrided the funX().So this class will have the new
implementation of funX(). ie class Y extend Z


If Multiple Inheritance is permitted in java, then if the
new programmer C inherited both the classes and he didn't
done any overriding of method funX() then if he calls the
funX() ,the JVM will not know which method to call i.e.,
either the method in class X or method in class Y.

Because of this inconsistencies,Multiple inheritance is not
permitted in java

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More Core Java Interview Questions

What’s a deadlock?

0 Answers  


Can we declare Pointer in Java?

5 Answers  


What access modifiers can be used for variables?

0 Answers  


What is the nested interface?

0 Answers  


Can we access the non-final local variable, inside the local inner class?

0 Answers  


What is the maximum size of hashmap in java?

0 Answers  


How to change value in arraylist java?

0 Answers  


What is JDBC Driver interface?How can you retrieve data from the ResultSet

0 Answers   CTS,


What are the Static and Dynamic Variables? Differentiate them.

0 Answers   CGI,


Explain the difference between a Thread and a Process.

0 Answers   Ciena,


How do you implement singleton class?

0 Answers  


Why is singleton instance static?

0 Answers  


Categories