answersLogoWhite

0


Best Answer

The superclass of all the classes in Java is Object,So any class we created is a instance of Object. Assume there is a class Father and Class Uncle,Now the class called child will have to inherit the features of father and Uncle which inturn will have some common features.So the child class would not be sure of whether to inherit the common feature from Father or uncle. This is known as the diamond problem - http://en.wikipedia.org/wiki/Diamond_problem

There is nothing like virtual in Java

User Avatar

Wiki User

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

Wiki User

9y ago

Multiple inheritance:

  • The concept of Getting the properties from multiple class objects to sub class object with same priorities is known as multiple inheritance.
  • Java Doesn't Support multiple Inheritance.
Diamond problem:
  • In multiple inheritance there is every chance of multiple properties of multiple objects with the same name available to the sub class object with same priorities leads for the ambiguity.
  • We have two classes B and c which are inheriting A class properties.
  • Here Class D inheriting B class and C class So properties present in those classes will be available in java.
  • But both classes are in same level with same priority.
  • If we want to use show() method that leads to ambiguity
  • This is called diamond problem.
  • Because of multiple inheritance there is chance of the root object getting created more than once.
  • Always the root object i.e object of object class hast to be created only once.
  • Because of above mentioned reasons multiple inheritance would not be supported by java.
  • Thus in java a class can not extend more than one class simultaneously. At most a class can extend only one class.

    source: instanceofjavaforus.blogspot.in/2014/12/why-java-does-not-supports-multiple.html

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Multiple inheritance creates what is known as the deadly diamond of death. Say that two classes(we'll say A and B) inherit the methods of one super class(we'll say X). And then another class (C) extends both and A and B(if multiple inheritance were allowed). If A and B have overrided a method in X differently and C calls a method based in X the compiler does not know which version to call. The A version or the B version. Some languages allow this but Java does not. Java does however use interfaces. Interfaces allow classes to inherit from multiple super classes but interface methods and variables are all static and final(meaning they cannot be extended as to avoid the deadly diamond).

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

Add your answer:

Earn +20 pts
Q: Why does java not support multiple inheritence?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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.


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 { ... .... ...... }


Does Java support copy constructor?

No. Java does not support copy constructor


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.

Related questions

Why JAVA cantt support multiple inheritence?

It's by design.


What are the alternatives to inheritence in java?

Java does not support multiple inheritance; a subclass cannot have more than one parent. Java compensates for this with interfaces. A class can implement multiple interfaces, but can only extend one class.


What does java not support?

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


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 is ambiguity in multiple inheritance?

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.


How do you achieve multiple inheritence using class in java?

Multiple Inheritance cannot be achieved only by using Classes in Java. You would have to use Interfaces as well to achieve multiple Inheritance. Java as such does not support direct multiple inheritance. We can have theoretical multiple inheritance by using interfaces using which you can outline the kind of functionality your child classes can have. For example you can have a declaration like this public class A implements X, Y, Z { } Here this class A would have to implement the methods that are declared in the interfaces X, Y & Z. So the outline of the functionality that A would have can be found by checking the interfaces but the exact implementation would depend on the programmer who codes class 'A'


How are interface used for multiple inheritence?

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.


Does inheritence effect child support?

Only if there are arrears.


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 { ... .... ...... }


Why do object-oriented programmers oppose using multiple inheritence?

Not all of them do; C++ uses multiple inheritance.The designers of Java decided to do away with several aspects of C++ that may cause confusion, this includes multiple inheritance, pointers, and several other aspects.The possible confusion with multiple inheritance arises when both parents have a method or field with the same name. Which one to use in the child?To have some of the benefits of multiple inheritance, Java supports interfaces instead. A class can implement multiple interfaces.


Difference object oriented language object based language?

object base: that are not use subtype or inheritence is called object base. object oriented: that use subtypes and inheritence is called object oriented e.g vb.net and java.