Java Class.getSuperclass()

Syntax

Class.getSuperclass() has the following syntax.

public Class <? super T> getSuperclass()

Example

In the following code shows how to use Class.getSuperclass() method.


/*  w w w  .j  av a2 s  . com*/
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.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable