• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OverLoading && Overrriding confused with output

 
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,



i am Ok with output displayed for c1.dep() (overridden) ,
Could any one please explain me how exactly we get output in as 'A' and 'C' in line 1 and line 2 .
 
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gowtham!!





I hope this helps you to atleast some extent..............
[ August 20, 2007: Message edited by: dhwani mathur ]
 
Ganesh Gowtham
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi mathur
Thanks for your reply .
see the below code .


i was bit even more confused .... but upto some extend i will agree with you .
see the output for the this code .i added one more method in class Az.
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The revised version doesn't do what you say it does: -



The original version does do what you say: -



In the original, there is no overriding of any of the m1(something) methods. The three classes provide three different overloads of it.

The variable c1 is declared to contain an Az object. When choosing between overloads, it is the declared type that determines what happens. There is only one method in Az that matches c1.m1(c2); it's the one that prints "A".

In the modified version, the class Az has a method m1(Cz) that is overridden in class Cz. When choosing between overrides, it is the run-time type that matters. So, because c1's run-time type is Cz, the method in Cz is called, printing "C".
[ August 20, 2007: Message edited by: Peter Chase ]
 
Ganesh Gowtham
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter ,
Thanks for replying .
Here c1 has object which refer;s to "Cz" class.
what you had mentioned in repy "The variable c1 is declared to contain an Az object" which comfuses me .

Please let me know if am wrong in understanding the concept.?
reply
    Bookmark Topic Watch Topic
  • New Topic