why multiple inheritance is not supported by java?
why multiple inheritance is not supported by java?
java was designed in that way it doesnt support syntactically but conceptually it is possible with interfaces
that is because if a child is inheriting from two classes ,and if both the parent classes have the same method (same signature and same return type),the compiler will be confused as the method in the child overrides which parent
in c++ also the multiple inheritance is there but due to ur saying reason we use the virtual function in c++.In java also we can use the virtual function so whats the deffect to use the multiple inheritance
actually we can use it,but indirectly witn the help of interfaces..
but my qs. is why not directly..?
what are actually interfaces?
Hi ,
Interface is the collection of methods with empty implementations and constants variables ( variables with static and final declarations ).
All the methods in an interface are "public and abstract" by default. Since interfaces are abstract in nature so they can not be directly instantiated.
To define the methods of an interface the keyword "implements" is used.
Eg:
interface check
{
public void message();
}
public class Interface {
public static void main(String[] args) {
try {
check t = new check() {
public void message() {
System.out.println("Method defined in the interface");
}
};
t.message();
} catch (Exception ex) {
System.out.println("" + ex.getMessage());
}
}
}
If any query let me know....
Thanks,
Riju.
i dont think just because making the java simple and robust we don't have mulitple inhertiance and if it so why do they provided Interface concept for us....
and one thing more that we can have same method name with same return type via METHOD OVERRIDING...
hi fnds
in java we have diamond property . i.m if the two parent class have the same method signature and different implementations the the jvm confused which parent class method it invoke....... this naming convention is called diamond property in java.
thats y in java it doesn't support multiple inheritance directly, but it suppots indirect multiple inheritance throw interfaces bcz if the two in interfaces having same name even thow that method implementation existeds only once in the child class .....so there is no confusion to jvm which method implementation it invoke.........