Java Class.getSimpleName()
Syntax
Class.getSimpleName() has the following syntax.
public String getSimpleName()
Example
In the following code shows how to use Class.getSimpleName() method.
/*from ww w.j a v a2s . com*/
public class Main {
public static void main(String[] args) {
Main c = new Main();
Class cls = c.getClass();
// returns the name of the class
String name = cls.getName();
System.out.println("Class Name = " + name);
// returns the simple name of the class
String sname = cls.getSimpleName();
System.out.println("Class SimpleName = " + sname);
}
}
The code above generates the following result.