Search This Blog

Thursday 14 August 2014

Get Super Class Name - JAVA

This program shows how to Get Super Class Name in Java.

Circle.java

/**
 * Circle Inherits from Shape
 *
 */
public class Circle extends Shape{
 
}

Shape.java

public class Shape {
 
 public static void main(String[] args){
  Object obj = new Circle();
  
  Class c = obj.getClass();
  
  System.out.println("Class name = " + c.getName()); //Circle
  System.out.println("Super Class = " + c.getSuperclass()); //Shape
  System.out.println("Super's super class = " + c.getSuperclass().getSuperclass()); //Object
 }
}

No comments:

Post a Comment