+ 6

Why does java not support multiple inheritance?

23rd Dec 2016, 11:32 AM
manish rawat
manish rawat - avatar
11 odpowiedzi
+ 6
Well, you can implement several interfaces, but you can't extend more than one class. It is because interfaces tell what you have to do and classes tell how to do it. For example, you implement two interfaces, that have same method: 1. int foo(); 2. int foo(); That is okay, because it just tell you have to implement this method. But if you could extend two classes with the same method: 1. int foo() { return 1; } 2. int foo() { return 2; } Now, you don't override this method and call it, what result would it return? That is why you can't extend more than one class in Java.
23rd Dec 2016, 1:40 PM
Gintaras Volkvičius
Gintaras Volkvičius - avatar
+ 3
I was told that the reason is avoiding program's complexity... in the later phasis of program development you might need to edit some classes...and it will be disastrous if there is multiple inheritance
23rd Dec 2016, 6:23 PM
Ahmad S Kanaan
Ahmad S Kanaan - avatar
+ 2
ohhh but we have this in c++ and to resolve this we inherit using virtual keyword. why not here. java is made later to c++ so it must have c++'s concepts. while it may be there will but must be some underlying reason🤔
23rd Dec 2016, 4:33 PM
manish rawat
manish rawat - avatar
+ 2
Java does not support multiple inheritance because the language was built to remove complexities of c++
26th Dec 2016, 8:57 PM
Ridwan
Ridwan - avatar
+ 1
To reduce the complexity and simplify the language multi inheritance is not supported in java
27th Dec 2016, 1:54 PM
Dhanya
0
hey mike😂😂
26th Dec 2016, 6:00 PM
manish rawat
manish rawat - avatar
0
@suspicious user i know what u mean by diamond. but same problem arise in c++ also and we solve it by simply using virtual keyword so why not in java??
26th Dec 2016, 6:40 PM
manish rawat
manish rawat - avatar
0
@ridwan this looks logical
27th Dec 2016, 4:51 AM
manish rawat
manish rawat - avatar
0
Multiple inheritance can be useful, but I've never found a good use for it other than to emulate Java's interfaces.
27th Dec 2016, 7:29 PM
Joe Sewell
Joe Sewell - avatar
0
it is better this way organization as a tree than organization as a net.
27th Dec 2016, 8:07 PM
Dejan Stojkovic
Dejan Stojkovic - avatar
- 1
ambiguity dude....single object... cannot refer multiple classes... that'll
27th Dec 2016, 1:42 PM
Deepak Sharma
Deepak Sharma - avatar