This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Runtime / Compile Time Behaviour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Runtime / Compile Time Behaviour" Watch "Runtime / Compile Time Behaviour" New topic
Author

Runtime / Compile Time Behaviour

Grant Malcom
Greenhorn

Joined: Nov 27, 2009
Posts: 1
Hi, EveryBody
Here is the Code , for Which i need some Explanation....

Now I get a Compile Error, at line# 13, Also, when the Method print with Integer Parameter is commented, then Program runs Fine, printing - String!, ( Why Not Object! was Printed )

Can Any one Explain the Behavior, is it anything to do with Runtime Polymorhisim.

Thanks in Advance!

Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
wait....letme give you a link which will explain it to you
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
http://faq.javaranch.com/java/ScjpFaq#mostSpecific
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
so this means that between String and object, String will be chosen as String extends object....now even Integer extends Object so now compiler is confused whether to chose String or Integer so you get an ambiguous error

i hope this clears it all
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
sorry
its
http://faq.javaranch.com/java/ScjpFaq#mostSpecific
 
 
subject: Runtime / Compile Time Behaviour