1.

For Name () Method Of Class Class?

Answer»
  • is USED to load the class dynamically.
  • returns the instance of Class class.
  • It should be used if you know the fully qualified name of class. This cannot be used for primitive types. 

Let's SEE the SIMPLE example of forName () method.

class Simple{}

class Test{

public STATIC void main(String ARGS[]){

Class c=Class.forName("Simple");

System.out.println(c.getName());

}

}

Output: Simple

Let's see the simple example of forName () method.

class Simple{}

class Test{

public static void main(String args[]){

Class c=Class.forName("Simple");

System.out.println(c.getName());

}

}

Output: Simple



Discussion

No Comment Found