QuizzesIntermediate Java Reflection: Dynamic Class Inspection & Modification
intermediate
java

Intermediate Java Reflection: Dynamic Class Inspection & Modification

Explore the intricacies of Java Reflection for dynamic class inspection and modification.

18 minutes 12 questions Pass at 70%
Time Limit
18 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

12 questions on Intermediate Java Reflection: Dynamic Class Inspection & Modification. Work through them here, then start the quiz to answer them and see your score.

  1. 1.Which of the following is a primary use of Java Reflection?

    • ATo manage memory allocation
    • BTo compile Java code
    • CTo inspect classes, interfaces, fields, and methods at runtime
    • DTo execute Java code faster
  2. 2.What is the purpose of the `getDeclaredMethods()` method in Java Reflection?

    • ATo retrieve all public methods of a class
    • BTo retrieve methods from superclass
    • CTo retrieve only static methods
    • DTo retrieve all methods declared in a class, including private ones
  3. 3.How can you create an instance of a class using Java Reflection?

    • AUsing `Class.forName().newInstance()`
    • BUsing `new Class()`
    • CUsing `Object.clone()`
    • DUsing `ClassLoader.loadClass()`
  4. 4.What exception might be thrown when accessing a private field using Reflection?

    • ANullPointerException
    • BClassNotFoundException
    • CIOException
    • DIllegalAccessException
  5. 5.Which method is used to change the value of a field using Reflection?

    • AField.update()
    • BField.change()
    • CField.set()
    • DField.modify()
  6. 6.What is the return type of `getSuperclass()` method in Java Reflection?

    • AString
    • Bvoid
    • CClass<?>
    • DObject
  7. 7.Which of the following can be modified using Java Reflection?

    • AClass names
    • BField values
    • CPackage names
    • DMethod signatures
  8. 8.What does `isAnnotationPresent(Class<? extends Annotation> annotationClass)` check?

    • AIf a field is static
    • BIf a class has a specific annotation
    • CIf a class is abstract
    • DIf a method is overridden
  9. 9.Which method would you use to obtain the name of a class using Reflection?

    • AClass.getName()
    • BClass.getSimpleName()
    • CClass.getClassName()
    • DClass.getTypeName()
  10. 10.What is the purpose of `Method.invoke(Object obj, Object... args)` in Reflection?

    • ATo create a new instance of a class
    • BTo get the name of a method
    • CTo call a method on an object
    • DTo check if a method is static
  11. 11.How can you access a private method of a class using Reflection?

    • ABy using `Method.unlock()`
    • BBy using `Method.access()`
    • CBy using `Method.open()`
    • DBy using `Method.setAccessible(true)`
  12. 12.Which Reflection method would you use to get all public fields of a class?

    • AgetAllFields()
    • BgetDeclaredFields()
    • CgetPublicFields()
    • DgetFields()