Java Method Overloading with Binary Literals
Short answer
C The binary literal resolves to int, calling the print(int) method which outputs hello.
Question

Key Takeaways
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.
Common mistake: Candidates often choose B because they assume the large binary value forces promotion to long, overlooking Java's literal type rules.
Expert Analysis
Why the Answer Is Correct
The correct answer is C because the binary literal 0b1101_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 a long; 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?
Why doesn't the large value cause overflow or exception?
Community Votes
100% of anonymous learners picked answer C. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 4 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.
From public community threads 4
-
james2033 👍 4 Answered Cpackage q10; public class Main { void print(int i) { System.out.println("hello"); } void print(long j) { System.out.println("there"); } public static void main(String[] args) { new Main().print(0b1101_1010); } } // Result: // hello
-
minhdev 👍 1Auto promote to int C is correct
-
Uteman 👍 1C is the correct answer
-
xplorerpj 👍 1 Answered CC is correct answer
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.