answersLogoWhite

0


Best Answer

Let me explain with a example.

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

Suppose a programmer ABC inherited the class Z to class X and overrided the funX().So this class will have the new implementation of funX().

Suppose a programmer DEF inherited the class Z to class Y and overrided the funX().So this class will have the new implementation of funX().

If Multiple Inheritance is permitted in java, then if the new programmer 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.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

Java supports a limited form a multiple inheritance by allowing a class to inherit from one other class and an unlimited number of interfaces. A full multiple inheritance capability was left out of the Java language to keep it simple and avoid abuse.

A skeletal example for multiple implementation:

interface Swimmer

{

public void swim();

}

interface Runner

{

public void run();

}

interface Biker

{

public void bike();

}

class Athlete

{

...

}

class TriathalonAthlete extends Athlete implements Swimmer, Runner, Biker

{

public void swim();

public void run();

public void bike();

}

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

-using interface multiple inheritance is achived in java.As given in following example

public interface PersonLike {
String getName();
int getAge();
}

and the EmployeeLike interface is:

public interface EmployeeLike {
float getSalary();
java.util.Date getHireDate();
}

public class Employee extends Person implements PersonLike, EmployeeLike {
// detail omitted
}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

The designers of Java decided it shouldn't have multiple inheritance. The reasons for that are the ambiguities that may arise with multiple inheritance - if the same method is inherited from both parents, which one should be used? Instead of multiple inheritance, Java supports interfaces, which provide part of the functionality of multiple inheritance.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Think about this scenario. Let us say the Automobile Class has a drive() method and the Car class has a drive() method and the Ferrari class has a drive() method too. Let us say you create a new class FerrariF12011 that looks like below:

Public class FerrariF12011 extends Ferrari, Car, Automobile {…}

And at some point of time you need to call the drive() method, what would happen? Your JVM wouldn't know which method to invoke and you may have to instantiate one of the classes that you already inherit in order to call its appropriate method. Sounds confusing right? To avoid this nonsense is why the creators of java did not include this direct multiple inheritance feature.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

think about this scenario. Let us say the Automobile Class has a drive() method and the Car class has a drive() method and the Ferrari class has a drive() method too. Let us say you create a new class FerrariF12011 that looks like below:

Public class FerrariF12011 extends Ferrari, Car, Automobile {…}

And at some point of time you need to call the drive() method, what would happen? Your JVM wouldn't know which method to invoke and you may have to instantiate one of the classes that you already inherit in order to call its appropriate method. Sounds confusing right? To avoid this nonsense is why the creators of java did not include this direct multiple inheritance feature

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

Multiple inheritance is achieved in Java using interfaces

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How multiple inheritance achived in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is ambiguity in multiple inheritance?

Java does not support multiple inheritance


What does java not support?

Java does not support multiple inheritance.......


Give the structure of multiple inheritance?

Java does not support multiple inheritance. It is done with the help of interfaces in java. a class can implement n number of interfaces, thus showing multiple inheritance. but a class cannot extend multiple classes in java.


What is problem in multiple inheritance?

Java does not support direct multiple Inheritance. Harder to implement, not every language support it: C++ does, Java does not.


What kind of inheritance is not allowed in java?

Java does not allow the multiple inheritance of concrete classes, though it does allow a "hybrid" inheritance of one concrete class and multiple interfaces.


How can you write multiple inheritance program in java?

Java does not support direct multiple inheritance. You can implement partial multiple inheritance using interfaces. ex: public class ExMultInherit implements interface1, interface2, interface 3 { ... .... ...... }


How ploymorphism and inheritance is different from that in Java and c plus plus?

C++ allows multiple inheritance while Java does not. In my opinion, multiple inheritance is not useful because it can get very confusing very quick. For polymorphism, C++ does early binding by default, while Java does late binding by default. Late binding is more useful than early binding.


Why you neet interface in java?

When you need the benefits of multiple inheritance while avoiding the DDD (Deadly Diamond of Death). Java doesn't allow multiple inheritance anyway.


Can we implement multiple inheritance in java using package and interface?

Yes. Java does not support full fledged/proper multiple inheritance. But, whatever partial inheritance that Java supports can be implemented using interfaces Actually, java does not support multiple inheritance. You can achieve partial multiple inheritance using interfaces but java is not like C or C++ where you can do direct multiple inheritance. However, you can achieve partial multiple inheritance with the help of interfaces. Ex: public class FerrariF12011 extends Ferrari implements Car, Automobile {…} And this is under the assumption that Car and Automobile are interfaces. Here if you see, though you don't inherit concrete code from the Car or the Automobile interface, you do inherit skeleton methods that determine the way your class eventually behaves and hence this can be considered partial Multiple Inheritance.


Need of interface in java?

Interfaces are used in Java to accomplish most of the goals of Multiple Inheritance. For several reasons, Java only supports Single Inheritance for classes - i.e. a class can have only a single parent. The use of Interfaces is how Java attempts to implement most of the positives of the concept of Multiple Inheritance while avoiding its pitfalls.


What is multiple inheritance in java?

Actually, java does not support multiple inheritance. You can achieve partial multiple inheritance using interfaces but java is not like C or C++ where you can do direct multiple inheritance. However, you can achieve partial multiple inheritance with the help of interfaces. Ex: public class FerrariF12011 extends Ferrari implements Car, Automobile {…} And this is under the assumption that Car and Automobile are interfaces. Here if you see, though you don't inherit concrete code from the Car or the Automobile interface, you do inherit skeleton methods that determine the way your class eventually behaves and hence this can be considered partial Multiple Inheritance.


How you possible multiple inheritance in java?

Actually, java does not support multiple inheritance. You can achieve partial multiple inheritance using interfaces but java is not like C or C++ where you can do direct multiple inheritance. However, you can achieve partial multiple inheritance with the help of interfaces. Ex: public class FerrariF12011 extends Ferrari implements Car, Automobile {…} And this is under the assumption that Car and Automobile are interfaces. Here if you see, though you don't inherit concrete code from the Car or the Automobile interface, you do inherit skeleton methods that determine the way your class eventually behaves and hence this can be considered partial Multiple Inheritance