answersLogoWhite

0

Why java doesnot support multiple inheritence?

Updated: 8/20/2019
User Avatar

Wiki User

9y ago

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

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why java doesnot support multiple inheritence?
Write your answer...
Submit
Still have questions?
magnify glass
imp
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.


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.


Why void is restriction in java main function?

becoz the main program doesnot return any value to the os.