Why java Don't Support Multiple interitence
Answers were Sorted based on User's Feedback
Answer / g ch vishnu vardhan reddy
Multiple Inheritance is not supported by java in order to
avoid ambiguity between variables of different classes and
to rudece memory overloading.
| Is This Answer Correct ? | 42 Yes | 1 No |
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.
| Is This Answer Correct ? | 29 Yes | 4 No |
Answer / midhula kadiyala
If you extend more than one class JVM does n't understand
for which object it has to create object first.so ambiguios
occurs.That's y java does n't support multiple inheritance.
We can implement multiple inheritance by using interfaces.
Interface A
{
public void X();
}
class B implements A
{
public void X()
{
s.o.p("this is function x");
}
public void Y()
{
s.o.p("this is function y");
}
}
class C extends B
{
public void X(){...}
public void j(){...}
P S V M()
{
A a =new C();
a.X();
}
}
if a class wants to extend 1 or more classes define those
function definitions in one interface and in another class
provide bodies by implementing those interface.
if the class can extend the class which is implementing that
interface then u can access all functions present in that
interface.
here my interface A
i provide bodies in class B by implementing interface A
class C extend that class B
and class c is able to access all the methods present in the
interface by creating the reference of an interface with the
object of class C
(remember 1 thing to the reference of interface we can
assign object of class only if it is implementing that
interface)
here class c extends class B and again class B implements
interface A
so i can write
A a= new C();
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sanjeev
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?
}
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / srinu
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
| Is This Answer Correct ? | 0 Yes | 2 No |
Answer / kiranksj
ya java don't support multiple interitence but by achieving
it the interface are came
| Is This Answer Correct ? | 2 Yes | 6 No |
Answer / sid
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
| Is This Answer Correct ? | 0 Yes | 4 No |
Answer / samir rana
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.
| Is This Answer Correct ? | 0 Yes | 4 No |
Why Wait and notify are kept in Object class although they are used only with Thread Class
2 Answers Global Logic, Saksoft,
Addition to previous section relative word 5th one was Putrid ans: rotten, also there was prob. in 1st section on bucket weight ans:10kg, also there was a prob. on train speed to find bridge length ans:800 mtrs.
Explain class A{} class B{} class C{} all the three classes are saved in a single file name, what the name should i provide to the file ,in what file name should i run the program? Ple Explain
What is the difference between I ++ and ++ I in java?
"we cannot create an object of interface but we can create a variable of it".diacuss the statement with the help of an example.
Which collections are thread safe in java?
What is the use of System class?
what is the purpose of class "Object" which is base class for all classes?
What are keyboard events?
Write a program to find maximum and minimum number in array?
What is nan in java?
What type of variable is error flag?