Skip to main content

Posts

Showing posts with the label Reflection in Java

Reflection Interview Questions in Java

Reflection 1. What is Reflection in Java? Reflection is Java language's ability to inspect and dynamically call classes, methods, attributes etc. at Runtime. It helps in examining or modifying the Runtime behavior of a class at Runtime. 2. What are the uses of Reflection in Java? Reflection is often used in Testing, Debugging and in Integrated Development Environment (IDE). Reflection allows you to write programs that do not have to "know" everything at compile time. It makes programs more dynamic, since they can be tied together at runtime. Many modern frameworks like Spring etc. use Reflection. Some modern languages like Python etc. also use Reflection. JAVA API for XML Parsing (JAXP) also uses Reflection. 3. How can we access private method of a class from outside the class? We can use Reflection to access private method of a class from outside the class. IN Java, we use getDeclaredMethod() to get instance of a private method. Then we ...