nerdexam
Oracle

1Z0-803 · Question #171

Given: What is the result?

The correct answer is C. Compilation fails. The program will fail to compile because Java requires local variables to be explicitly initialized before they are used.

Java Basics

Question

Given:

What is the result?

Exhibit

1Z0-803 question #171 exhibit

Options

  • AInitialized
  • BInitialized
  • CCompilation fails
  • DAn exception is thrown at runtime

How the community answered

(34 responses)
  • A
    3% (1)
  • C
    94% (32)
  • D
    3% (1)

Why each option

The program will fail to compile because Java requires local variables to be explicitly initialized before they are used.

AInitialized

If a local variable is uninitialized, the code will not successfully execute to produce an output like 'Initialized' because it will not compile.

BInitialized

Successful execution and output are not possible if the program fails to compile due to an uninitialized local variable.

CCompilation failsCorrect

Java enforces a rule that local variables must be explicitly assigned a value before they are accessed or used in any operation. Failing to initialize a local variable before its first use results in a compile-time error, preventing the program from being built.

DAn exception is thrown at runtime

An uninitialized local variable is a compile-time error, not a runtime exception; the compiler detects and flags this issue during the build process.

Concept tested: Java local variable initialization

Source: https://docs.oracle.com/javase/specs/jls/se11/html/jls-4.html#jls-4.12.5

Topics

#compilation error#syntax error

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice