Skip to content
Sharp

Reflection API · interview question

Why do teams use setAccessible(true) in Java reflection in production code?

Multiple choiceEasychapter-16-curatedpremiumreflection-apidynamic-class-loading
Choose one answer
Answer and explanation

Correct answer

A. It allows access to private members of a class.

Why

setAccessible(true) allows reflective access to private members of a class, breaking encapsulation and enabling inspection or modification of otherwise inaccessible data.

Test yourself on Reflection API

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

Start free test
All Reflection API questions →