Saturday, 16 August 2014

getSuperclass() : Get the Super class of this class

You can get the super class of given class using 'getSuperclass' method of java.lang.Class.

import java.util.*;

public class GetSuperClass {
    public static void main(String args[]){
        HashSet<Integer> mySet = new HashSet<> ();
        Class superClass = mySet.getClass().getSuperclass();
        
        System.out.print("Super class of class HashSet is : ");
        System.out.println(superClass.getName());
    }
}

Output
Super class of class HashSet is : java.util.AbstractSet


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment