Exam 1z0-829 All QuestionsBrowse all questions from this exam
Question 10

Given:

What is the result?

    Correct Answer: B

    The method new Main().print(0b1101_1010) calls the print method with the binary value 0b1101_1010, which is 218 in decimal. In Java, a binary literal prefixed with 0b is considered an integer. However, 218 exceeds the range of a byte type (which is -128 to 127) and therefore fits within the range of an int. But since both int and long can accommodate 218, Java will prefer the more specific method when possible. Thus, it will choose print(long j) because method resolution in Java chooses the narrowest possible type when an exact match isn't found, leading to the result 'there'.

Discussion
james2033Option: C

package 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

UtemanOption: C

C is the correct answer

xplorerpjOption: C

C is correct answer

minhdevOption: C

Auto promote to int C is correct