Skip to content
Sharp

Reflection API · interview question

What does the method call 'setAccessible(true)' achieve when applied to a Field object in Java?

Multiple choiceEasychapter-16-curatedpremiumreflection-apibreaking-encapsulation
Choose one answer
Answer and explanation

Correct answer

D. It allows changing the private field's value.

Why

Calling 'setAccessible(true)' on a Field object bypasses Java's access control checks, allowing you to read and modify private fields. This is useful in framework development but should be used carefully.

Test yourself on Reflection API

A free test with instant, explained results. No account needed.

Start free test
All Reflection API questions →