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…
Question
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)- A10% (3)
- B79% (23)
- C7% (2)
- D3% (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
staticvariable belongs to the class, not to an instance - calling it an "instance variable" withstaticis a contradiction in terms. - C is illegal:
abstractmeans "must be overridden," butprivatemeans "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
publicor package-private (no keyword) are allowed;protectedis 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
Community Discussion
No community discussion yet for this question.