Skip to content
Sharp

Reflection API · interview question

In the context of Java reflection, what is the primary purpose of calling setAccessible(true) on a Field object?

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

Correct answer

D. To bypass Java language access checks for that field

Why

Calling setAccessible(true) allows you to bypass the access control checks of the Java language, enabling you to read and modify private fields, but it doesn't change the field's access level permanently.

Test yourself on Reflection API

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

Start free test
All Reflection API questions →