Class.getSuperclass() has the following syntax.
public Class <? super T> getSuperclass()
In the following code shows how to use Class.getSuperclass() method.
/*from www . j a va2 s . c o m*/ class superClass { // super class } class subClass extends superClass { // sub class } public class Main { public static void main(String args[]) { superClass val1 = new superClass(); subClass val2 = new subClass(); Class cls = val1.getClass(); System.out.println(cls.getName()); cls = cls.getSuperclass(); System.out.println(cls.getName()); cls = val2.getClass(); System.out.println(cls.getName()); } }
The code above generates the following result.