fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.  
  11. static class ClassB {
  12. }
  13.  
  14. static class ClassA extends ClassB {
  15. }
  16.  
  17. static void printHierarchy (Class<?> clz) {
  18. if (clz != null) {
  19. System.out.println(clz.getSimpleName());
  20. System.out.print("inherits from: ");
  21. printHierarchy(clz.getSuperclass());
  22. } else {
  23. System.out.println("nothing");
  24. }
  25. }
  26.  
  27. public static void main (String[] args) {
  28. printHierarchy(ClassA.class);
  29. }
  30.  
  31. }
Success #stdin #stdout #stderr 0.04s 711168KB
stdin
Standard input is empty
stdout
ClassA
inherits from: ClassB
inherits from: Object
inherits from: nothing
stderr
Java HotSpot(TM) Client VM warning: No monotonic clock was available - timed services may be adversely affected if the time-of-day clock changes