Skip to content
Sharp

Java Annotations · interview question

When using custom annotations in Java, which retention policy must be specified to ensure annotations are available at runtime?

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

Correct answer

A. RUNTIME

Why

RetentionPolicy.RUNTIME ensures that annotations are retained at runtime, allowing them to be accessed via reflection. This is essential for frameworks that need to inspect annotations during execution.

Test yourself on Java Annotations

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

Start free test
All Java Annotations questions →