QuizzesUnderstanding Java Reflection API & Dynamic Proxy
beginner
java

Understanding Java Reflection API & Dynamic Proxy

A beginner's quiz on the basics of Java Reflection API and Dynamic Proxy.

15 minutes 15 questions Pass at 70%
Time Limit
15 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

15 questions on Understanding Java Reflection API & Dynamic Proxy. Work through them here, then start the quiz to answer them and see your score.

  1. 1.What is the primary purpose of the Java Reflection API?

    • ATo execute Java code faster
    • BTo manage memory allocation
    • CTo inspect and manipulate classes, methods, and fields at runtime
    • DTo compile Java code
  2. 2.Which method is used to obtain the Class object of a class named 'Example'?

    • Anew Example().getClass()
    • BExample.class
    • CClass.forName('Example')
    • DExample.getClass()
  3. 3.How can you create an instance of a class using Reflection?

    • AUsing Class.newInstance()
    • BUsing Class.forName()
    • CUsing Class.getName()
    • DUsing ClassLoader.loadClass()
  4. 4.Which of the following is a limitation of using Java Reflection?

    • AIt is only available in Java 8 and above
    • BIt cannot access private fields
    • CIt increases runtime performance overhead
    • DIt can only be used with interfaces
  5. 5.What is a Dynamic Proxy in Java?

    • AA class that implements multiple interfaces
    • BA static method in the Proxy class
    • CA proxy class that is created at runtime
    • DA class that extends another class
  6. 6.Which interface must be implemented to create a Dynamic Proxy?

    • ACallable
    • BProxyHandler
    • CInvocationHandler
    • DRunnable
  7. 7.How do you create a Dynamic Proxy instance?

    • AUsing Class.forName()
    • BUsing Proxy.newProxyInstance()
    • CUsing Class.newInstance()
    • DUsing Proxy.create()
  8. 8.What is required to use the Reflection API to access a private field?

    • AThe field must be declared in an interface
    • BThe field must be declared as static
    • CThe field must be declared as final
    • DThe field's accessibility must be changed using setAccessible(true)
  9. 9.Which of the following is NOT a use case for Java Reflection?

    • AInspecting class methods
    • BAccessing private fields
    • CInvoking methods dynamically
    • DCreating new classes at runtime
  10. 10.What is the return type of the getMethods() method in the Class class?

    • AMap<String, Method>
    • BMethod[]
    • CSet<Method>
    • DList<Method>
  11. 11.Which package contains the Java Reflection API?

    • Ajava.net
    • Bjava.io
    • Cjava.util
    • Djava.lang.reflect
  12. 12.What does the getDeclaredFields() method return?

    • AAll public fields of the class
    • BAll static fields
    • CAll inherited fields
    • DAll fields declared by the class
  13. 13.Which method is used to invoke a method using Reflection?

    • AMethod.call()
    • BMethod.execute()
    • CMethod.run()
    • DMethod.invoke()
  14. 14.What is the role of the Proxy class in Java?

    • ATo compile Java code
    • BTo create dynamic proxies
    • CTo create static proxies
    • DTo manage memory allocation
  15. 15.Which of the following is true about Reflection?

    • AIt can only be used in Java 11 and above
    • BIt allows runtime inspection of classes
    • CIt requires classes to be final
    • DIt can only be used with public classes