+ 6
Why does java not support multiple inheritance?
12 Respuestas
+ 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.
+ 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
+ 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🤔
+ 2
Java does not support multiple inheritance because the language was built to remove complexities of c++
+ 1
To reduce the complexity and simplify the language multi inheritance is not supported in java
0
hey mike😂😂
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??
0
@ridwan this looks logical
0
Multiple inheritance can be useful, but I've never found a good use for it other than to emulate Java's interfaces.
0
it is better this way organization as a tree than organization as a net.
- 1
ambiguity dude....single object... cannot refer multiple classes... that'll