What is the result?

Given the code fragment:

System.out.println(“Result: ” +3+5);
System.out.println(“result: ” + (3+5));

What is the result?

Given the code fragment:

System.out.println(“Result: ” +3+5);
System.out.println(“result: ” + (3+5));

What is the result?

A.
Result: 8
Result: 8

B.
Result: 35
Result: 8

C.
Result: 8
Result: 35

D.
Result: 35
Result: 35

Explanation:
In the first statement 3 and 5 are treated as strings and are simply concatenated. In the first statement 3 and 5 are treated as integers and their sum is calculated.



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Jazz

Jazz

“B”

Explanation:

“+” is to add/concat/display.
“+(a+b)” – according to BODMAS.

James

James

The Answer is B. See question #14 for more details.

Hans

Hans

Question #14?