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 *


Bahaa Khateib

Bahaa Khateib

correct, if s is a String builder compilation failed please keep this point in mind