Skip to content
Sharp

Java Annotations · interview question

Why does setAccessible(true) on a private field when using reflection change runtime behavior?

Multiple choiceHardchapter-16-curatedpremiumjava-annotationscustom-annotations
Choose one answer
Answer and explanation

Correct answer

C. It allows modification of the field's value.

Why

setAccessible(true) temporarily allows access to private fields, enabling both reading and modification, which is useful in testing or frameworks.

Test yourself on Java Annotations

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

Start free test
All Java Annotations questions →