Basics of Java Reflection & Dynamic Proxies
A beginner's quiz on understanding Java Reflection and Dynamic Proxies.
Questions in this quiz
15 questions on Basics of Java Reflection & Dynamic Proxies. Work through them here, then start the quiz to answer them and see your score.
1.What is Java Reflection primarily used for?
- ATo perform network operations
- BTo dynamically inspect classes, methods, and fields at runtime
- CTo manage memory allocation
- DTo compile Java code
2.Which package contains the classes for Java Reflection?
- Ajava.util
- Bjava.io
- Cjava.net
- Djava.lang.reflect
3.What is a dynamic proxy in Java?
- AA method for encrypting data
- BA class that implements interfaces at runtime
- CA tool for debugging network connections
- DA proxy that can change its IP address
4.Which method is used to create a dynamic proxy instance?
- AObject.clone()
- BProxy.newProxyInstance()
- CSystem.getProperty()
- DClass.forName()
5.What does the getDeclaredMethods() method return?
- AAll declared methods of a class, excluding inherited ones
- BOnly public methods of a class
- COnly private methods of a class
- DAll methods of a class, including inherited ones
6.Which interface must be implemented to handle method calls on a dynamic proxy instance?
- ASerializable
- BRunnable
- CInvocationHandler
- DCallable
7.How can you access a private field of a class using reflection?
- AUsing the getField() method
- BUsing the getMethod() method
- CUsing the getDeclaredField() method and setAccessible(true)
- DUsing the getConstructor() method
8.What is the purpose of the Method.invoke() method in Java Reflection?
- ATo retrieve the name of a method
- BTo create a new instance of a class
- CTo invoke a method on an object
- DTo list all methods of a class
9.What is required to create a dynamic proxy for an interface?
- AThe interface must have a default constructor
- BAn implementation of InvocationHandler
- CThe interface must extend another interface
- DThe interface must be annotated with @Proxy
10.Which of the following is a limitation of Java Reflection?
- AIt cannot access private fields
- BIt requires Java 11 or higher
- CIt can only be used with abstract classes
- DIt can lead to performance overhead
11.What does the getClass() method return?
- AThe class loader of an object
- BThe runtime class of an object
- CThe superclass of an object
- DThe package name of an object
12.Which of these is NOT a use case for Java Reflection?
- ACreating a new instance of a class
- BAccessing private fields
- CInspecting class metadata
- DCompiling Java code
13.What does the getInterfaces() method of a Class object return?
- AAll fields of a class
- BAll methods of a class
- CAll classes implemented by a class
- DAll interfaces implemented by a class
14.What is the role of the Proxy class in Java?
- ATo handle file I/O operations
- BTo manage network connections
- CTo create dynamic proxy classes and instances
- DTo perform mathematical calculations
15.Which method is used to obtain the superclass of a class using reflection?
- AgetAncestorClass()
- BgetBaseClass()
- CgetParentClass()
- DgetSuperclass()