Home > AI > Language > Java >

getSuperClass

Example code:

import java.lang.*;

class SuperClass {
    // super class
}

class SubClass extends SuperClass {
    // sub class
}

public class ClassDemo {

    public static void main(String args[]) {

        SuperClass supC = new SuperClass();
        SubClass subC = new SubClass();
        Class cls;

        cls = supC.getClass();
        System.out.println("val1 is object of type = " + cls.getName());

        cls = cls.getSuperclass();
        System.out.println("super class of val1 = " + cls.getName());



        cls = subC.getClass();
        System.out.println("val2 is object of type = " + cls.getName());

        cls = cls.getSuperclass();
        System.out.println("super class of val2 = " + cls.getName());
    }
}

Leave a Reply