What is the result?

Given:

String s = new String(“3”);

System.out.print(1 + 2 + s + 4 + 5);

What is the result?

Given:

String s = new String(“3”);

System.out.print(1 + 2 + s + 4 + 5);

What is the result?

A.
12345

B.
3345

C.
1239

D.
339

E.
Compilation fails.

Explanation:
1 and 2 are added. Then the string s is concatenated.
Finally 3 and 4 are concatenated as strings.



Leave a Reply 2

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


pavan

pavan

1+2 = 3
3+”3″=”33″
“33”+4+5= 3345

B is correct