• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

overriding

 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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().
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it 'overriding'? I think its 'overloading'.
[ October 03, 2007: Message edited by: Sarah Jorden ]
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry overlooked !
 
srinivas sridaragaddi
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Is this the real life? Is this just fantasy? Is this a tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic