Courseiva
Java Basics and SyntaxeasyMultiple ChoiceObjective-mapped

1Z0-811 Java Basics and Syntax Practice Question

A developer declares an integer variable inside a method but does not assign a value. What is the result of attempting to print the variable?

⚠ Common exam trap

Oracle often tests the distinction between local variables (which must be initialized) and instance/class fields (which get default values), trapping candidates who assume all variables default to 0 or null.

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 error

In Java, local variables (declared inside a method) must be initialized before use. The compiler performs definite assignment analysis and will reject code that attempts to read an uninitialized local variable, producing a compilation error. This rule ensures memory safety and prevents undefined behavior.

Answer analysis

Option-by-option breakdown

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

  • Prints null

    Why it's wrong here

    null is not a valid value for primitive int.

  • Compilation error

    Why this is correct

    Local variables must be initialized before use.

  • Prints 0

    Why it's wrong here

    Local variables do not have default values; only class fields do.

  • Runtime exception

    Why it's wrong here

    The error occurs at compile time, not runtime.

About these practice questions

One of 481 original 1Z0-811 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.