How do I get direct superclass and interfaces of a class?

Java reflection also dealing with inheritance concepts. You can get the direct interfaces and direct super class of a class by using method getInterfaces() and getSuperclass() of java.lang.Class object.

  • getInterfaces() will returns an array of Class objects that represent the direct super interfaces of the target Class object.
  • getSuperclass() will returns the Class object representing the direct super class of the target Class object or null if the target represents Object class, an interface, a primitive type, or void.
package org.kodejava.example.lang.reflect;

import javax.swing.*;
import java.util.Date;

public class GetSuperClassDemo {
    public static void main(String[] args) {

    public static void get(Class clazz) {
        // Gets array of direct interface of clazz object
        Class[] interfaces = clazz.getInterfaces();

        System.out.format("Direct Interfaces of %s:%n",
        for (Class clz : interfaces) {

        // Gets direct superclass of clazz object
        Class superclz = clazz.getSuperclass();
        System.out.format("Direct Superclass of %s: is %s %n",
                clazz.getName(), superclz.getName());

Here is the result of the code snippet:

Direct Interfaces of java.lang.String:
Direct Superclass of java.lang.String: is java.lang.Object 
Direct Interfaces of java.util.Date:
Direct Superclass of java.util.Date: is java.lang.Object 
Direct Interfaces of javax.swing.JButton:
Direct Superclass of javax.swing.JButton: is javax.swing.AbstractButton 
Direct Interfaces of javax.swing.Timer:
Direct Superclass of javax.swing.Timer: is java.lang.Object 

Wayan Saryada

Founder at Kode Java Org
I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. If these posts help, you can support me, buy me a cup of coffee or tea. Thank you 🥳

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.