Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unexpected Output?

 
Thapliyal Akshat
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Akshat
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please please please ... Code tags...
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 15.12.2.5: Choosing the Most Specific Method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic