Skip to content
Sharp

Java Annotations · interview question

How can you dynamically execute a method in Java using reflection?

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

Correct answer

B. Using the Method.invoke method

Why

The Method.invoke method allows you to dynamically execute a method using reflection. You need to obtain a Method object representing the method and then call invoke on it with the appropriate parameters.

Test yourself on Java Annotations

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

Start free test
All Java Annotations questions →