Java Reflection and Dynamic Class Loading Basics
An introductory quiz on Java Reflection API and Dynamic Class Loading.
Questions in this quiz
15 questions on Java Reflection and Dynamic Class Loading Basics. Work through them here, then start the quiz to answer them and see your score.
1.What is Java Reflection primarily used for?
- ATo manipulate arrays
- BTo perform file I/O operations
- CTo inspect and modify classes, methods, and fields at runtime
- DTo handle exceptions
2.Which class in Java is used to obtain metadata of a class using Reflection?
- AMetaData
- BClassLoader
- CReflection
- DClass
3.How can you dynamically load a class in Java?
- AUsing Scanner
- BUsing Class.forName()
- CUsing System.load()
- DUsing FileReader
4.Which method is used to create an instance of a class using Reflection?
- AcreateInstance()
- BgetInstance()
- CnewInstance()
- DinstanceOf()
5.What does the getDeclaredMethods() method return?
- AOnly static methods of a class
- BAll methods of a class, both public and private
- CAll public methods of a class
- DOnly private methods of a class
6.Which of the following is NOT a use case of Java Reflection?
- ATesting frameworks
- BDynamic proxies
- CDependency injection
- DFile manipulation
7.What exception might be thrown when using Class.forName()?
- AIOException
- BNullPointerException
- CClassNotFoundException
- DArithmeticException
8.Which method is used to access a private field using Reflection?
- AsetField()
- BgetField()
- CaccessField()
- DsetAccessible(true)
9.What is the purpose of the Method.invoke() method?
- ATo delete a method
- BTo list all methods
- CTo call a method on an object
- DTo create a new method
10.Which of the following is true about dynamic class loading?
- AClasses are loaded at shutdown
- BClasses are loaded at compile time
- CClasses are loaded at runtime
- DClasses are never loaded
11.What does the getFields() method return?
- AAll public fields of a class
- BOnly private fields of a class
- CAll fields of a class, both public and private
- DOnly static fields of a class
12.Which interface must be implemented for a class to be loaded by a custom class loader?
- ACloneable
- BClassLoader
- CSerializable
- DRunnable
13.What is the purpose of the getConstructor() method in Reflection?
- ATo retrieve a specific constructor of a class
- BTo list all constructors
- CTo delete a constructor
- DTo create a new constructor
14.Which of the following is a disadvantage of using Reflection?
- ASimplified code
- BSecurity restrictions
- CImproved readability
- DIncreased performance
15.What is the result of calling getName() on a Class object?
- AThe package name
- BThe superclass name
- CThe class name
- DThe method name