Question discussion

What is the output of the following Java program?public class Main { public static void main(String[] args) { System.out.println(1 + 2 + "3…

2147Medium DSSSB TGT Computer Science 0 replies

What is the output of the following Java program?

public class Main {
    public static void main(String[] args) {
        System.out.println(1 + 2 + "3" + 4 + 5);
    }
}
  • A15
  • B12345
  • C339
  • D3345
Correct answer: D

Explanation

The expression is evaluated left to right: 1 + 2 = 3 (numeric), then "3" turns it into the string "33", and 4 and 5 are appended one by one, giving 3345.

Discussion 0

Nobody has replied yet. Start the discussion!