1Z0-811 Primitives, Strings and Operators Practice Question
What is the output of System.out.println(1 + 2 + "3" + 4 + 5);?
⚠ Common exam trap
Candidates often assume all `+` operators behave the same way, failing to recognize that the presence of a string literal changes the operator's meaning from arithmetic addition to string concatenation, and that left-to-right evaluation means the first two numbers are added as integers before the string is encountered.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
3345
Java evaluates the expression left-to-right. The first operation is `1 + 2`, which is integer addition, yielding `3`. Then `3 + "3"` triggers string concatenation, producing `"33"`. The remaining `+ 4` and `+ 5` are also string concatenations, appending `"4"` and `"5"` to give `"3345"`. The `println` method outputs this string.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
3345
Why this is correct
String concatenation after first addition.
- ✗
12345
Why it's wrong here
Addition is left associative; numbers before string are added.
- ✗
3"3"45
Why it's wrong here
No quotes printed.
- ✗
15
Why it's wrong here
Misunderstands concatenation.
Go deeper
Related to this question
About these practice questions
This 1Z0-811 question is part of Courseiva's 481-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
Same concept, more angles
2 more ways this is tested on 1Z0-811
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. What is the output?
easy- ✓ A.Result: 23
- B.Result: 2 3
- C.Result: 5
- D.Result: 2+3
Why A: The code `System.out.println("Result: " + 2 + 3);` uses string concatenation. In Java, the `+` operator is left-associative, so the expression is evaluated as `("Result: " + 2) + 3`. First, the integer `2` is converted to the string `"2"` and concatenated with `"Result: "` to form `"Result: 2"`. Then, the integer `3` is converted to the string `"3"` and concatenated, producing `"Result: 23"`. Option A is correct because the output is the string `"Result: 23"`.
Variation 2. What is the result of: System.out.println(10 + 20 + "30");
easy- A.102030
- ✓ B.3030
- C.30
- D.Compilation fails
Why B: In Java, the '+' operator is left-associative. The expression `10 + 20 + "30"` is evaluated as `(10 + 20) + "30"`, which first performs integer addition to get `30`, then concatenates that integer with the string `"30"`, resulting in the string `"3030"`. The `System.out.println` method then prints the string `3030`.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.