Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overriding

 
srinivas sridaragaddi
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.
 
suresh mulagala
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it 'overriding'? I think its 'overloading'.
[ October 03, 2007: Message edited by: Sarah Jorden ]
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
suresh mulagala
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry overlooked !
 
srinivas sridaragaddi
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic