Java Reflection API: Beginner's Exploration
A beginner-level quiz to explore the basics of Java Reflection API.
Questions in this quiz
15 questions on Java Reflection API: Beginner's Exploration. Work through them here, then start the quiz to answer them and see your score.
1.What is the primary purpose of the Java Reflection API?
- ATo inspect and modify classes, methods, and fields at runtime
- BTo manipulate files
- CTo handle exceptions
- DTo perform network operations
2.Which class is used to obtain the class object in Java Reflection?
- AClass
- BField
- CObject
- DMethod
3.How do you obtain the Class object for a given object instance?
- Ainstance.getClass()
- Binstance.getClassName()
- CClass.forName("classname")
- Dnew Class()
4.Which method is used to retrieve all declared methods of a class?
- AgetMethods()
- BgetAllMethods()
- CgetClassMethods()
- DgetDeclaredMethods()
5.What does the getFields() method return?
- ANo fields
- BAll fields including private
- COnly private fields
- DOnly public fields
6.Which method allows you to invoke a method using reflection?
- AinvokeMethod()
- Binvoke()
- Cexecute()
- Dcall()
7.What is required to access private fields using reflection?
- ADirect access
- BNo special requirement
- CUse of setAccessible(true)
- DUse of getPrivateField()
8.Which exception is thrown if a class is not found during reflection?
- AInvocationTargetException
- BClassNotFoundException
- CIllegalAccessException
- DNoSuchMethodException
9.What does the getConstructor() method return?
- ANo constructors
- BAll constructors
- COnly public constructors
- DA single constructor
10.How can you change the value of a field using reflection?
- Afield.modify()
- Bfield.set(Object obj, Object value)
- Cfield.setValue()
- Dfield.set()
11.What is the return type of the getName() method in the Class class?
- Aboolean
- Bvoid
- Cint
- DString
12.Which method is used to retrieve the superclass of a class?
- AgetSuperclass()
- BgetParentClass()
- CgetBaseClass()
- DgetSuper()
13.What does the isInterface() method determine?
- AIf a class is public
- BIf a class is abstract
- CIf a class is an interface
- DIf a class is final
14.Which method retrieves the package information of a class?
- AgetClassPackage()
- BgetPackage()
- CgetPackageName()
- DgetPackageInfo()
15.What is the output of getModifiers() method?
- AA float
- BA String
- CAn integer
- DA boolean