What is the super class of every class in Java?


The class named Object is the super class of every class in Java.

Let’s test it with an example. The java.lang.Class.getSuperclass() returns the Class representing the superclass of the entity (class, interface, primitive type or void) represented by this Class.

So, Create a sample concrete class and lets try to get the name of its super class using this method.

Example

Live Demo

public class Test {
   public static void main(String args[]){
      Test obj = new Test();
      Class cls = obj.getClass().getSuperclass();
      System.out.println(cls.getName());
   }
}

Output

Since the Object class is the super class of all classes it displays the name of the object class as shown below.

java.lang.Object

Updated on: 30-Jul-2019

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements