Java Reflection: Understanding Runtime Type Information
Explore the basics of Java Reflection and how it provides runtime type information.
Questions in this quiz
15 questions on Java Reflection: Understanding Runtime Type Information. Work through them here, then start the quiz to answer them and see your score.
1.What is Java Reflection primarily used for?
- AManaging memory allocation
- BCompiling Java code
- CHandling exceptions
- DAccessing private fields and methods
2.Which class is central to Java Reflection?
- AObject
- BReflectionClass
- CMethod
- DClass
3.How can you obtain a Class object for a given class?
- AUsing the getClass() method
- BUsing the new keyword
- CUsing the Reflection API
- DUsing the Class.forName() method
4.Which method is used to get the name of a class using reflection?
- AgetTypeName()
- BgetSimpleName()
- CgetClassName()
- DgetName()
5.What does the getDeclaredFields() method return?
- AOnly public fields
- BOnly private fields
- CAll fields of the class, including inherited
- DAll fields declared in the class
6.Which method would you use to invoke a method using reflection?
- AinvokeMethod()
- Bexecute()
- Cinvoke()
- Dcall()
7.What is required to access a private field using reflection?
- AUse the get() method
- BSet the field to public
- CUse the getField() method
- DCall setAccessible(true)
8.Which method retrieves all methods declared in a class?
- AgetClassMethods()
- BgetMethods()
- CgetAllMethods()
- DgetDeclaredMethods()
9.What is the return type of the getFields() method?
- ASet<Field>
- BMap<String, Field>
- CField[]
- DList<Field>
10.How do you check if a class is an interface using reflection?
- AisAbstract()
- BisClass()
- CisType()
- DisInterface()
11.What does the getConstructors() method return?
- AAll constructors of the class
- BOnly private constructors
- CAll constructors including inherited
- DOnly public constructors
12.Which method is used to create a new instance of a class using reflection?
- Ainstantiate()
- Bcreate()
- Cconstruct()
- DnewInstance()
13.What exception is thrown if a class is not found using Class.forName()?
- AClassNotFoundException
- BNoClassDefFoundError
- CIllegalAccessException
- DInstantiationException
14.Which method retrieves the superclass of a class using reflection?
- AgetParentClass()
- BgetBaseClass()
- CgetSuperclass()
- DgetAncestorClass()
15.What is the purpose of the getModifiers() method in reflection?
- ATo get the class name
- BTo get the method names
- CTo get the field values
- DTo get the access modifiers