Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

All super classes of a class

Tags:

java

oop

I have a 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 know how I could do that in java?

like image 917
Makky Avatar asked Apr 15 '11 15:04

Makky


People also ask

What is the super class of all the classes?

The class named Object is the super class of every class in Java.

How many super classes can a class have?

The class from which the subclass is derived is called a superclass (also a base class or a parent class). Excepting Object , which has no superclass, every class has one and only one direct superclass (single inheritance).

How do I find out my class super class?

To determine the superclass of a class, you invoke the getSuperclass method. This method returns a Class object representing the superclass, or returns null if the class has no superclass.

Which class is the super class of every class in Java?

A: The Object class, which is stored in the java. lang package, is the ultimate superclass of all Java classes (except for Object ).


1 Answers

Use Class.getSuperClass() to traverse the hierarchy.

Class C = getClass(); while (C != null) {   System.out.println(C.getName());   C = C.getSuperclass(); } 
like image 199
Erik Avatar answered Oct 02 '22 10:10

Erik