What is the super class of every class in Java?

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 08-Jan-2018 05:05:36
Advertisements