Given the code fragment
What is the result?
A. Result A 1 Result B 3
B. Result A 01 Result B 3
C. Result A 01
Result B 12
D. Result A 1
Result B 12
Given the code fragment
What is the result?
A. Result A 1 Result B 3
B. Result A 01 Result B 3
C. Result A 01
Result B 12
D. Result A 1
Result B 12
Result A 01
Result B 12
Option : C
if ints where on the left side arithmetic would be performed then sum would be concatenated with the string
C:
#javac Test2.java
#java Test2
Result A01
Result B12
Answer C:
If either of the operands is String, then the operation is concatenation. And since the numbers are on the right hand side, the concatenation precedes.
Answer is C
public class Test {
public static void main(String[] args) {
System.out.println(“Result A ” + 0 + 1);
System.out.println(“Result B ” + (1) + (2));
}
}
C