There is a big reason behind that(java does not support
multiple inheritance). Please go through the following
example.
1. Assume that java is supporting multiple inheritance
class A {
void m1() {
// implement method
}
}
class B {
void m1() {
// implement method
}
}
//As for the assumption (1) the following code will compile
class C extends A,B {
public static void main( String s[]) {
C c = new C();
c.m1();
}
}
Note : In main method i am calling c.m1() method In this
situation which super class m1 method has to call (from A
or B) JVM will confuse.
So our assumtion(1) is wrong .
This is the reason why java does not support multple
inheritance through classes.
Note : This same cocept is applicable for classes.
The famous "diamond shaped problem " is the reason behind NOT using multiple inheritance in java.
check out this link for full details
http://en.wikipedia.org/wiki/Diamond_problem
java support multiple inheritance not through the use of
class, but through the implementation of interface we can
achieve multiple inheritance.
By using interface we can implement multiple interfaces for
a class which can solve the problem of our multiple inheritance.
Java Does not support Multiple inhertiance through class
because ambiguity between variables of different classes
and to rudece memory overloading.and another reason java
extended only one class at time
java support Multiple inhertiance through interfaces.because
java class implements any number of interface at time
Why cant we face same ambiguity when we declare variables?
interface A{
int i = 10;
}
interface B{
int i = 20;
}
Class C implement A, B{
what is the value of C.i?
}
Does a class inherit the constructor of its super class?if
it does, how can you hide that constructor? if it doesnot
how can you call it from the sub class?