View Single Post
  #3 (permalink)
Old 4th July 2008, 02:14 PM
shalini_goel14
CE - Apprentice
 
shalini_goel14's Avatar
 
I'm a Crazy Computer Science Engineer
Join Date: 12th March 2008
Location: India
Posts: 34
Send a message via Yahoo to shalini_goel14
Default Re: Java-Multiple inheritance

Check the following scenario:
class A{
void method1(){
//some code here
}
}

class B{
void method1(){
// some code here
}
class C extends A,B { //do not try..not possible in java
//assuming it inherits method1() method

}
class JavaMultipleInheritenceTest{
public static void main(String args[]){
C cObj=new C();
cObj.method1();//creates an ambiguous situation for JVM to detect which
class's overridden method method1() it is asking for(classA or class B)

}
}
This is the reason in Java we cannot extend multiple classes but can extend multiple interfaces.
__________________
"If people never did silly things, nothing intelligent would ever get done" -Ludwig Wittgenstein
shalini_goel14 is online now   Reply With Quote