Java Class.getName()
Syntax
Class.getName() has the following syntax.
public String getName()
Example
In the following code shows how to use Class.getName() method.
/*w ww . j a v a 2s . c o m*/
public class Main {
public static void main(String[] args) {
Main cl = new Main();
Class c1Class = cl.getClass();
// returns the name of the class
String name = c1Class.getName();
System.out.println(name);
}
}
The code above generates the following result.