Skip to content
Sharp

Java Annotations · interview question

How do you declare a custom annotation that should be retained at runtime?

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

Correct answer

C. @Retention(RetentionPolicy.RUNTIME)

Why

To retain an annotation at runtime, you must declare it with @Retention(RetentionPolicy.RUNTIME). This ensures the annotation is available for inspection and use during the program's execution.

Test yourself on Java Annotations

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

Start free test
All Java Annotations questions →