| Author |
overriding
|
srinivas sridaragaddi
Ranch Hand
Joined: Jul 24, 2007
Posts: 225
|
|
output:abc can somebody explain me the output. i was thinking its a compiler error as d1.m1(a1) where a1 is d1 fails i.e is-a test fails.
|
SCJP 5.0<br /> <br />"Skills are started with learning and mastered with improvement. Nothing is hereditary except death" BUDDHA...
|
 |
suresh mulagala
Ranch Hand
Joined: Feb 18, 2003
Posts: 41
|
|
a1 is the superclass and you are overriding m1, so d1.m1(a1) is valid and prints "a" and so on and so forth... here it is evaluating to A's method because you are passing in an instance of A().
|
 |
Sarah Jorden
Greenhorn
Joined: Sep 26, 2007
Posts: 16
|
|
Is it 'overriding'? I think its 'overloading'. [ October 03, 2007: Message edited by: Sarah Jorden ]
|
 |
Burkhard Hassel
Ranch Hand
Joined: Aug 25, 2006
Posts: 1274
|
|
Howdy! The answer of Suresh (and the thread subject title) is wrong. You are not overriding anything, you are overloading. Test3 has got four seperate (but overloaded, and three of them inherited) m1-methods: void m1(A a){...} inherited void m1(B b){...} inherited void m1(C c){...} inherited void m1(Test3 d){...} own Therefore also your notion that a1 IS_NOT-A Test3 is correct but irrelevant in this context. Which method will be choosen? Always the most specific one. Check the FAQ page for "most specific method". Yours, Bu.
|
all events occur in real time
|
 |
suresh mulagala
Ranch Hand
Joined: Feb 18, 2003
Posts: 41
|
|
|
sorry overlooked !
|
 |
srinivas sridaragaddi
Ranch Hand
Joined: Jul 24, 2007
Posts: 225
|
|
|
Thanks Bu for your reply, due to lack of resources i post my doubts at a time, so their was a confusion between overloading and overiding.
|
 |
 |
|
|
subject: overriding
|
|
|