Skip to content
Sharp

Reflection API · interview question

How can frameworks dynamically map URL routes to private method handlers using Java Reflection?

Multiple choiceMediumchapter-16-curatedpremiumreflection-apibreaking-encapsulation
java
Method method = handlerClass.getDeclaredMethod("handleRequest");
Choose one answer
Answer and explanation

Correct answer

B. By invoking methods using 'Method.invoke()'

Why

Frameworks use Reflection's 'Method.invoke()' to dynamically call method handlers, even if they are private, by first setting them accessible. This allows URL routes to be mapped to methods without changing method visibility.

Test yourself on Reflection API

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

Start free test
All Reflection API questions →