Skip to content
Sharp

Java Annotations · interview question

How does breaking encapsulation using setAccessible(true) impact a Java application?

Multiple choiceHardchapter-16-curatedpremiumjava-annotationsannotation-processors
Choose one answer
Answer and explanation

Correct answer

D. It may compromise security and violate encapsulation principles.

Why

Using setAccessible(true) allows accessing private fields and methods, which can compromise security and violate encapsulation principles, making the code fragile and harder to maintain.

Test yourself on Java Annotations

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

Start free test
All Java Annotations questions →