Skip to content
Sharp

Java Annotations · interview question

Which API would you use to check if a class is annotated with a specific annotation at runtime?

Multiple choiceMediumchapter-16-curatedpremiumjava-annotationscustom-annotations
Choose one answer
Answer and explanation

Correct answer

C. Class.isAnnotationPresent

Why

The Class.isAnnotationPresent method checks if a specific annotation is present on a class at runtime. This is useful when you need to apply certain behaviors or logic based on the presence of annotations.

Test yourself on Java Annotations

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

Start free test
All Java Annotations questions →