Courseiva
Exception Handling and Development ToolsmediumMultiple ChoiceObjective-mapped

1Z0-811 Exception Handling and Development Tools Practice Question

Consider the following code snippet:

public int getValue() {

try {

return 1;
    } catch (Exception e) {
        return 2;
    } finally {
        return 3;
    }
}

What does the method return?

⚠ Common exam trap

Oracle often tests the misconception that a `finally` block cannot override a `try` block's return value, or that the `finally` block runs after the method has already returned, leading candidates to incorrectly choose option D (1) or option C (2).

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

3

(3) because a `finally` block always executes after the `try` block, and if the `finally` block contains a `return` statement, that return value overrides any return value from the `try` or `catch` blocks. In Java, the `finally` block's `return` statement causes the method to exit with the value 3, regardless of what the `try` block attempted to return.

Answer analysis

Option-by-option breakdown

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

  • 3

    Why this is correct

    The finally block executes and its return statement takes precedence, returning 3.

  • The code does not compile.

    Why it's wrong here

    The code compiles; it is legal to have return in finally, though it is bad practice.

  • 2

    Why it's wrong here

    No exception occurs, so catch is skipped, but finally still overrides.

  • 1

    Why it's wrong here

    The finally's return overrides the try's return.

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 →

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.