1
visibility

What will be the output of below statements?

String s = “Java”+1+2+”Quiz”+””+(3+4);
System.out.println(s);

  • A

    Java3Quiz7

  • B

    Java12Quiz7

  • C

    Java12Quiz34

  • D

    Java3Quiz34

First of all, the expression in the bracket is executed. Then it’s all + operators, so they get executed from left to right.

We get String with each concatenation, hence the output gets produced as shown below.

“Java”+1+2+”Quiz”+””+(3+4)
= “Java”+1+2+”Quiz”+””+7
= “Java1″+2+”Quiz”+””+7
= “Java12″+”Quiz”+””+7
= “Java12Quiz”+””+7
= “Java12Quiz”+7
= “Java12Quiz7”