Finding Superclasses

Class cls = obj.getClass();
											Class superclass = cls.getSuperclass();

The ancestors of a given class are referred to as that class’s superclasses. Using reflection, you can determine all of the ancestors of a given class. After you’ve obtained a Class object, you can use the getSuperclass() method to get the class’s superclass if one exists. If a superclass exists, a Class object will be returned. If there is not a superclass, this method will return null. Remember that Java supports only single inheritance, so for any given class, there can be only one superclass. Actually to be clear, there can be only one direct superclass. Technically, all ancestor classes are considered to be superclasses of a given class. To retrieve ...

Get Java™ Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.