Given the code fragment: What is the result?
A.
Result: 8 Result: 8
B.
Result: 35 Result: 8
C.
Result: 8 Result: 35
D.
Result: 35 Result: 35
Given the code fragment: What is the result?
A.
Result: 8 Result: 8
B.
Result: 35 Result: 8
C.
Result: 8 Result: 35
D.
Result: 35 Result: 35
B
Answer: B
Explanation:
In the first println the + operation is used for string concatenation so the printed value will be this one:
Result: 35
In the second println we see that the addition operation is being enclosed with “()”. In this case the arithmetic operation will be executed before the string concatenation so as a result the printed value will be this one:
Result: 8