Courseiva
Java Basics and SyntaxmediumMultiple ChoiceObjective-mapped

1Z0-811 Java Basics and Syntax Practice Question

Exhibit

public class MyClass {
    public static void main(String[] args) {
        int num = 10;
        if(num = 5) {
            System.out.println("Five");
        }
    }
}

Refer to the exhibit. What happens when you compile this code?

⚠ Common exam trap

Oracle often tests the distinction between using a final variable in a switch expression (allowed) versus attempting to reassign it inside the switch body (not allowed), leading candidates to incorrectly assume that final variables can be modified in any context.

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

Compilation fails because num is final

The code fails to compile because the variable `num` is declared as `final`, meaning its value cannot be changed after initialization. The switch statement attempts to assign a new value to `num` in each case label (e.g., `case 1: num = 5;`), which results in a compilation error: cannot assign a value to a final variable. This is not a type mismatch; it is a violation of the final constraint.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Compilation fails because of type mismatch

    Why it's wrong here

    Correct. The compilation fails because the final variable `num` cannot be reassigned. The error is a compilation error due to final variable modification.

  • Compilation fails because num is final

    Why this is correct

    Incorrect. Although `num` is final, the specific error is a type mismatch because assigning to a final variable is illegal. The option's phrasing is too vague.

  • Prints "Five"

    Why it's wrong here

    Incorrect. The code does not compile, so it cannot print "Five."

  • Prints nothing

    Why it's wrong here

    Incorrect. The code does not compile, so it cannot print nothing.

About these practice questions

Courseiva writes every 1Z0-811 question from scratch — 481 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 →

How Courseiva writes practice questions · Editorial policy

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.