File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Unexpected Output? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Unexpected Output?" Watch "Unexpected Output?" New topic

Unexpected Output?

Thapliyal Akshat

Joined: Jun 04, 2009
Posts: 29
The below program prints CC. How? Why its not giving ambiguity error? How null gets type casted into C.

Sorry for not using the Code tag before posting this post. Post Updated as per your recommendations.

Thanks and Regards,
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Please please please ... Code tags...

JDBCSupport - An easy to use, light-weight JDBC framework -
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15081

When the Java compiler has to choose between a number of alternative methods that match a method call, it will choose the most specific one, if there is no ambiguity. In this case, the method that takes two Cs is the most specific one.

For the exact details see the Java Language Specification, paragraph Choosing the Most Specific Method.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: Unexpected Output?
It's not a secret anymore!