What will be the output of the below code snippet? public class Quiz2 { public static void main(String args[]) { String letters = "ABC"; char[] numbers = { '1', '2', '3' }; System.out.println(letters + " easy as " + numbers); } }
-
ABC easy as [C@3e25a5
-
ABC easy as 123
-
ABC easy as 1 2 3
-
ABC easy as 1,2,3
A
Correct answer
Explanation
When concatenating a String with a char array using + operator, Java calls toString() on the char array, which doesn't return the array contents but rather its default Object toString() format (className + hexadecimal hash code). So "ABC easy as " + numbers produces "ABC easy as [C@3e25a5" (or similar hash). Options B, C, and D are incorrect - char arrays are not automatically converted to their string contents in concatenation. You need to use Arrays.toString() or new String(char[]) to get the actual characters.