This applet shows the inheritance level of a given object, which uses a recursive algorithm that can display all the interfaces and implementations of the object inherited. //Hierarchy.javaimport java.util. *; Import javax.swing. *;
public class Hierarchy {public static void showSuperClasses (Class c) {Class superClass = c.getSuperclass (); if (superClass = null!) {prt (superClass.getName ()); showSuperClasses (superClass);}}
Public Static Void ShowsuperClasses (Object O) {ShowSuperClasses (O.GetClass ());}
Public static void showinterfaces (class c) {class [] interfaces = c.GetInterface (); for (int i = 0; i Public Static Void Showinterfaces (Object O) {Showinterface (O.GetClass ());} Public static void showhierarchy (class c) {class superclass = c.getsuperclass (); class [] interfaces = c.GetInterfaces (); IF (superclass! = null) {PRT ("extends:"); prt (superclass.getname ()); showhierarchy (superclass);} For (int i = 0; I Public Static Void Showhierarchy (Object O) {Showhierarchy (O.GetClass ());} Public Static Void PRT (String S) {System.out.Println (s);} Public static void main (string [] args) {// showSUPERCLASSES (New ArrayList ()); // showinterface (new arraylist ()); showhierarchy (new z1 ());}} Interface a1 {} Interface A2 Extends A1 {} Interface b1 {} Interface B2 Extends B1 {} Interface C1 {} Interface C2 Extends C1 {} Class X1 Implements A2 {} Class Y1 Implements B2 {} Class Z1 EXTENDS X1 IMPLEments C2 {}