import java.util.*; import java.awt.*; import java.awt.event.*; public class Origins { // some test objects to be picked at random static Object[] objectCollection = { new FileDialog(new Frame()), new Properties(), new KeyEvent(null, 0,0,0,0, 'X') }; //------------------------------------------------------------------- // main() entry point //------------------------------------------------------------------- public static void main (String[] args) { int pick; Object object; Class objectClass; // pick an object at random pick = (int) (Math.random() * objectCollection.length); pick %= objectCollection.length; // guarantee 0..n-1 index object = objectCollection[pick]; // determine its type objectClass = object.getClass(); System.out.println("Chosen object is of type " + objectClass.getName()); // determine its inheritance tree System.out.println("Object's class inherits from:"); String tabs = " ->"; while ( objectClass.getSuperclass() != null ) { objectClass = objectClass.getSuperclass(); System.out.println(tabs + objectClass.getName()); tabs = " "+ tabs; } // determine its set of implemented interfaces objectClass = object.getClass(); System.out.println("and implements the following interfaces:"); Class interfaces[] = objectClass.getInterfaces(); if ( interfaces.length > 0 ) { for (int i=0; i < interfaces.length; i++) { System.out.println(" - " + interfaces[i].getName()); } } else { System.out.println("(none)"); } } } // End of Class Origins