Java MCQ
JAVA TRICKY input and output MCQ
What is the output of: System.out.println(10 + 20 + "Java");
Addition happens from left to right: 10+20=30, then 30+"Java"="30Java".
What is the output of: System.out.println("Java" + 10 + 20);
Once string concatenation starts, everything is treated as string: "Java"+"10"+"20"="Java1020".
What is the output of: System.out.println(10 + 20 + "Java" + 10 + 20);
10+20=30, 30+"Java"="30Java", "30Java"+10="30Java10", "30Java10"+20="30Java1020".
What is the output of: System.out.printf("%d %s", "Java", 10);
%d expects integer but gets "Java" (string), causing runtime exception.
What is the output of: System.out.println("Java" + null);
String concatenation converts null to "null" string.
What is the output of: String s = null; System.out.println(s + "Java");
String concatenation handles null gracefully, converting it to "null" string.
What is the output of: System.out.println('A' + 'B');
char addition uses ASCII values: 'A'(65) + 'B'(66) = 131.
What is the output of: System.out.println("A" + "B");
String concatenation: "A" + "B" = "AB".
What is the output of: System.out.println(1 + 2 + "3" + 4 + 5);
1+2=3, 3+"3"="33", "33"+4="334", "334"+5="3345".
What is the output of: System.out.println(String.valueOf(null));
String.valueOf(null) is ambiguous - it could match String.valueOf(char[]) or String.valueOf(Object). The compiler chooses char[] version, but null char array causes NPE.