Java · Question 1 · Easy

What will be the output of the following Java program?

public class Main {
    public static void main(String[] args) {
        System.out.println(1 + 2 + "3" + 4 + 5);
    }
}
  1. 15
  2. 12345
  3. 339
  4. 3345
Answer and explanation

Answer: D. 3345

Explanation: + is evaluated left to right. 1 + 2 is integer addition (3); 3 + "3" becomes the string "33"; after that every + is string concatenation, giving "3345".

Next: What will be the output of the following Java program?

Practise java

Try a fresh set of java questions with an explanation after every answer, free and without signing up: Java practice. Or sit a full placement mock test.

More java questions

More technical & programming practice

Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge