1Z0-811 Primitives, Strings and Operators Practice Question
Which of the following correctly uses the ternary operator to set int max to the larger of two ints x and y?
⚠ Common exam trap
Oracle often tests the exact syntax of the ternary operator, specifically that the colon `:` is required to separate the true and false expressions, and that the operator returns a value, not a statement like `if`.
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
✓
int max = x > y ? x : y;
The ternary operator `? :` evaluates the boolean expression `x > y`; if true, it returns `x`, otherwise `y`, assigning the larger value to `int max`. This is the standard syntax for a conditional assignment in Java, as defined in the Java Language Specification (JLS §15.25).
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
int max = x > y ? x : y;
Why this is correct
Correct syntax.
- ✗
int max = x > y ? y : x;
Why it's wrong here
This returns the smaller.
- ✗
int max = if (x > y) x else y;
Why it's wrong here
Not valid Java syntax.
- ✗
int max = (x > y) ? x, y;
Why it's wrong here
Comma not allowed.
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 →
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.