Class C = getClass(); while (C != null) {   System.out.println(C.getName());   C = C.getSuperclass(); }

Read more of this post