Reflections in Java


Reflections in Java


Reflection enables Java code to discover information about the fields, methods and constructors of loaded classes, and to use reflected fields, methods, and constructors to operate on their underlying counterparts, within security restrictions. The API accommodates applications that need access to either the public members of a target object (based on its runtime class) or the members declared by a given class. It also allows programs to suppress default reflective access control. (Source : Oracle)

Our First Program for understanding reflections in Java


1. For using reflections we have to import package names java.lang.reflect


 import java.lang.reflect.*;

abstract class A

{

}

class DesiExplanation

{

public static void main(String ar[])

{

Class cc=A.class;

System.out.println(Modifier.isAbstract(cc.getModifiers()));

}

}




Fun Fact : Java means cup of tea but it isn't everyone's cup of tea ~ Krishan Kumar

Comments

Popular posts from this blog

ACCESSING FUNCTION OF ONE CLASS FROM OTHER CLASS IN JAVA

CREATING OBJECT USING REFLECTION