This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes OverLoading && Overrriding confused with output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "OverLoading && Overrriding confused with output" Watch "OverLoading && Overrriding confused with output" New topic
Author

OverLoading && Overrriding confused with output

Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

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 .


Thanks, Ganesh Gowtham
http://ganesh.gowtham.googlepages.com
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
Hi Gowtham!!





I hope this helps you to atleast some extent..............
[ August 20, 2007: Message edited by: dhwani mathur ]
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

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.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
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 ]

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

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.?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OverLoading && Overrriding confused with output
 
Similar Threads
how many objects will be eligible for garbage collection
Overload method
method overriding
Polymorphisam
Overloading and Overriding