Skip to content
Sharp

Java Annotations · interview question

Which Java reflection method can be used to inspect the annotations present on a method during runtime?

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

Correct answer

B. Method.getAnnotations()

Why

Method.getAnnotations() retrieves all annotations present on a method at runtime. This is essential for frameworks that need to dynamically adjust behavior based on annotations.

Test yourself on Java Annotations

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

Start free test
All Java Annotations questions →