1Z0-829 Controlling Program Flow Practice Question
Given: Object obj = "Hello"; String result = switch(obj) { case String s -> "String of length " + s.length(); case Integer i -> "Integer"; default -> "Unknown"; }; What is result?
⚠ Common exam trap
A common mix-up: candidates think the switch requires a constant expression or that pattern matching is not allowed, leading them to expect a compilation error, or they may forget that the String case matches the runtime type, not the compile-time type of the reference.
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
✓
"String of length 5"
The switch expression uses pattern matching with type patterns. The runtime type of obj is String, so the first case matches, binding the value to s and executing the expression "String of length " + s.length(). Since s is "Hello", s.length() returns 5, so result is "String of length 5". Option C is correct.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
"Unknown"
Why it's wrong here
Incorrect; the String case matches.
- ✗
Compilation error
Why it's wrong here
Incorrect; the switch expression is valid.
- ✓
"String of length 5"
Why this is correct
Correct: the String pattern matches and length is 5.
- ✗
"Integer"
Why it's wrong here
Incorrect; obj is not an Integer.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 1Z0-829 question from scratch — 513 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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-829 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-829 exam.