Example usage for java.lang Class getSuperclass

List of usage examples for java.lang Class getSuperclass

Introduction

In this page you can find the example usage for java.lang Class getSuperclass.

Prototype

@HotSpotIntrinsicCandidate
public native Class<? super T> getSuperclass();

Source Link

Document

Returns the Class representing the direct superclass of the entity (class, interface, primitive type or void) represented by this Class .

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Class cls = int.class;
    Class sup = cls.getSuperclass(); // null
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Class cls = java.lang.Cloneable.class;
    Class sup = cls.getSuperclass(); // null
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Class cls = java.lang.String.class;
    Class sup = cls.getSuperclass(); // java.lang.Object

    cls = java.lang.Object.class;
    sup = cls.getSuperclass(); // null
}

From source file:MainClass.java

public static void main(String[] args) {
    String name = "java.util.Date";
    try {//from w  w  w.j a v a  2 s  .  com
        Class cl = Class.forName(name);
        Class supercl = cl.getSuperclass();
        System.out.println("class " + name);
        System.out.println("Its methods:");
        printFields(cl);
        System.out.println();
    } catch (ClassNotFoundException e) {
        System.out.println("Class not found.");
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    String name = "java.util.Date";
    try {/*from w  w  w  .j  av  a  2 s . co  m*/
        Class cl = Class.forName(name);
        Class supercl = cl.getSuperclass();
        System.out.println("class " + name);
        System.out.println("Its methods:");
        printMethods(cl);
        System.out.println();
    } catch (ClassNotFoundException e) {
        System.out.println("Class not found.");
    }
}

From source file:ReflectionTest.java

public static void main(String[] args) {
    String name = "java.util.Date";
    try {/*from   w w w.j  a  v  a  2s .  c  o  m*/
        Class cl = Class.forName(name);
        Class supercl = cl.getSuperclass();
        System.out.print("class " + name);
        if (supercl != null && !supercl.equals(Object.class))
            System.out.println(" extends " + supercl.getName());
        System.out.print("Its constructors:");
        printConstructors(cl);
        System.out.println();
    } catch (ClassNotFoundException e) {
        System.out.println("Class not found.");
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Class cc = null;
    cc = Main.class;
    System.out.println("The name of the superclass is " + cc.getSuperclass());
    System.out.println("Is SalariedEmployee an interface? " + cc.isInterface());
}

From source file:superClass.java

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());

}

From source file:InheritedMethods.java

public static void main(String... args) {
    try {/*ww w .  java 2 s .c  o m*/
        Class<?> c = Class.forName(args[0]);
        printMethods(c);

        Class parent = c.getSuperclass();
        while (parent != null) {
            printMethods(parent);
            parent = parent.getSuperclass();
        }

        // production code should handle this exception more gracefully
    } catch (ClassNotFoundException x) {
        x.printStackTrace();
    }
}

From source file:ReflectionTest.java

public static void main(String[] args) {
    // read class name from command line args or user input
    String name;//from  ww  w  .  j a va  2s .  c  o  m
    if (args.length > 0)
        name = args[0];
    else {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter class name (e.g. java.util.Date): ");
        name = in.next();
    }

    try {
        // print class name and superclass name (if != Object)
        Class cl = Class.forName(name);
        Class supercl = cl.getSuperclass();
        String modifiers = Modifier.toString(cl.getModifiers());
        if (modifiers.length() > 0)
            System.out.print(modifiers + " ");
        System.out.print("class " + name);
        if (supercl != null && supercl != Object.class)
            System.out.print(" extends " + supercl.getName());

        System.out.print("\n{\n");
        printConstructors(cl);
        System.out.println();
        printMethods(cl);
        System.out.println();
        printFields(cl);
        System.out.println("}");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    System.exit(0);
}