File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Strange o/p.Polymorphism in Overrided method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Strange o/p.Polymorphism in Overrided method?" Watch "Strange o/p.Polymorphism in Overrided method?" New topic

Strange o/p.Polymorphism in Overrided method?

Micheal John
Ranch Hand

Joined: Nov 01, 2006
Posts: 344

For the above pgm, how the o/p is: AAA

In all the three classes m1 has been overrided and polymorphism will come to play. so the below line
A3 a4 = new C3();
ref var is A3 and resolved at compile time, but while run time it has to call the C3 object's m1() only.. how it's calling A3 object's m1()?

Micheal John
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2398
Notice there is no overriding because the methods do not have the same signatures.
Satish Kota
Ranch Hand

Joined: Feb 08, 2006
Posts: 88
You are not overriding you are overloading the methods. And which methods to be called will be determined by the referenced type

SCJP 5.0 77%
I agree. Here's the link:
subject: Strange o/p.Polymorphism in Overrided method?
It's not a secret anymore!