Oracle
1Z0-803 · Question #120
1Z0-803 Question #120: Real Exam Question with Answer & Explanation
The correct answer is C: changing the string literals in each case label to integer. See the full explanation below for the reasoning.
Question
Given: class Test { public static void main (String[] args) { int day = 1; switch (day) { case "7": System.out.print("Uranus"); case "6": System.out.print("Saturn"); case "1": System.out.print("Mercury"); case "2": System.out.print("Venus"); case "3": System.out.print("Earth"); case "4": System.out.print("Mars"); case "5": System.out.print("Jupiter"); } } } Which two modifications, made independently, enable the code to compile and run?
Options
- Aadding a break statement after each print statement
- Badding a default section within the switch code-block
- Cchanging the string literals in each case label to integer
- Dchanging the type of the variable day to String
- Earranging the case labels in ascending order
Community Discussion
No community discussion yet for this question.