All superclasses in a class

advertisements

I have class that extends to another class and that class extends to another class.

class 1 extends class 2
class 2 extends class 3
class 3 extends class 4
class 4 extends class 5
class 5 extends class 6

Now i want to find all super classes of class 1.

anyone how I could that in java?


Use Class.getSuperClass() to traverse the hierarchy.

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