Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unexpected Output?

 
Thapliyal Akshat
Greenhorn
Posts: 29
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please please please ... Code tags...
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic