Java Method Overloading with Binary Literals
Given: What is the result? - 
Community Votes
100% of anonymous learners picked answer C. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
The exam tests whether you know that binary literals default to int unless suffixed with 'L', which traps candidates expecting long promotion.
This question tests Java method overloading resolution when passing a binary literal to overloaded integer types. It establishes that the literal resolves to int, invoking the int-based method.
Candidates often choose B because they assume the large binary value forces promotion to long, overlooking Java's literal type rules.
Community Discussion (4 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
The correct answer is C because the binary literal0b1101_1010 is treated as an int by default in Java. The print(int i) method is invoked, printing "hello".Why the Other Options Are Wrong
Option B is incorrect because the literal does not automatically become along; it only becomes a long if suffixed with L. Option A is wrong as the code compiles successfully. Option D is incorrect because the value fits within an int range.Community Comment Notes
The community overwhelmingly agrees with C. As user james2033 noted, the result is "hello" because the binary literal defaults to int. Others confirmed that auto-promotion to int logic applies here for standard binary literals.Exam Strategy
Always check the suffix of numeric literals. If there is no 'L', binary, hex, and octal literals are int type, regardless of their magnitude (as long as they fit in int).
Frequently Asked Questions
Does a binary literal ever default to long?
Only if it is explicitly suffixed with an uppercase L (e.g., 0b1101_1010L). Otherwise, it is always an int.
Why doesn't the large value cause overflow or exception?
The value 0b1101_1010 (218 decimal) fits comfortably within the positive range of a 32-bit signed int.