Skip to content
Sharp

Reflection API · interview question

How does using getDeclaredConstructor().newInstance() differ from using new MyClass()?

Multiple choiceMediumchapter-16-curatedpremiumreflection-apidynamic-class-loading
Choose one answer
Answer and explanation

Correct answer

C. Allows instantiation without knowing the type at compile-time.

Why

getDeclaredConstructor().newInstance() allows instantiation when the class type is not known at compile-time, supporting more dynamic and flexible code structures.

Test yourself on Reflection API

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

Start free test
All Reflection API questions →