Skip to content
Sharp

Java Annotations · interview question

Why does the setAccessible(true) method in Java reflection matter in practice?

Multiple choiceEasychapter-16-curatedpremiumjava-annotationsretention-policies
Choose one answer
Answer and explanation

Correct answer

B. To break encapsulation and access private members

Why

setAccessible(true) is used to override Java's access control checks, allowing the program to access private fields and methods. It is a powerful feature of reflection, often used in testing and framework development.

Test yourself on Java Annotations

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

Start free test
All Java Annotations questions →