Skip to content
Sharp

Java Annotations · interview question

Which Java annotation indicates that a custom annotation should be retained at runtime?

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

Correct answer

D. @Retention(RetentionPolicy.RUNTIME)

Why

The @Retention(RetentionPolicy.RUNTIME) annotation specifies that the annotated type should be retained by the JVM so they can be read reflectively at runtime.

Test yourself on Java Annotations

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

Start free test
All Java Annotations questions →