Skip to content
Sharp

Reflection API · interview question

How would you explain a potential security risk of using 'setAccessible(true)' with Reflection in an interview?

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

Correct answer

A. Exposing private data to unauthorized access

Why

Using 'setAccessible(true)' can expose private data to unauthorized access and modification, which can lead to security vulnerabilities. It should be used cautiously, especially in production environments.

Test yourself on Reflection API

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

Start free test
All Reflection API questions →