*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "overriding" Watch "overriding" New topic
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: overriding
 
Similar Threads
Method invocation doubt
Inheritance
Method Invocation
Could any one of you explain me this code
overriding & overloading