Skip to content
Sharp

Reflection API · interview question

Given a class instance, how can you obtain all methods declared in that class using reflection?

Multiple choiceMediumchapter-16-curatedpremiumreflection-apimethod-invoke
Choose one answer
Answer and explanation

Correct answer

A. Instance.getClass().getDeclaredMethods()

Why

getDeclaredMethods() is called on the class object obtained from instance.getClass() and it returns all methods declared in the class, including private ones.

Test yourself on Reflection API

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

Start free test
All Reflection API questions →