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);
}
}
- 15
- 12345
- 339
- 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
- What will be the output of the following Java program?
- Which Java keyword, when applied to a class, prevents any other class from…
- What will be the output of the following Java program?
- What is the default value of an int instance variable (field) that is declared…
- What will be the output of the following Java program?
- What will be the output of the following Java program?
- What will be the output of the following Java program?
- What will be the output of the following Java program?
- What will be the output of the following Java program?
- What will be the output of the following Java program?
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