nerdexam
Oracle

1Z0-819 · Question #150

Which statement about access modifiers is correct?

The correct answer is B. A local variable can be declared with the final modifier. Option B is correct because final is a valid modifier for local variables in Java - it simply prevents the variable from being reassigned after its initial value is set, which is commonly used to enforce immutability within a method or to allow a variable to be used inside a…

Java Object-Oriented Approach

Question

Which statement about access modifiers is correct?

Options

  • AAn instance variable can be declared with the static modifier.
  • BA local variable can be declared with the final modifier.
  • CAn abstract method can be declared with the private modifier.
  • DAn inner class cannot be declared with the public modifier.
  • EAn interface can be declared with the protected modifier

How the community answered

(29 responses)
  • A
    10% (3)
  • B
    79% (23)
  • C
    7% (2)
  • D
    3% (1)

Explanation

Option B is correct because final is a valid modifier for local variables in Java - it simply prevents the variable from being reassigned after its initial value is set, which is commonly used to enforce immutability within a method or to allow a variable to be used inside a lambda.

Why the distractors are wrong:

  • A is a category error: a static variable belongs to the class, not to an instance - calling it an "instance variable" with static is a contradiction in terms.
  • C is illegal: abstract means "must be overridden," but private means "not visible to subclasses," making the combination a compile-time error.
  • D is false: inner classes can carry any access modifier - public, protected, private, or package-private.
  • E is false for top-level interfaces: only public or package-private (no keyword) are allowed; protected is not a valid modifier for a top-level type.

Memory tip: Think "final is about reassignment, not scope" - it works on fields, parameters, and local variables. For the distractors, remember the rule: modifiers that conflict in meaning (abstract+private, static+instance) are always illegal, and top-level types can never be protected.

Topics

#Access Modifiers#Final Modifier#Local Variables#Java Syntax Rules

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice