-2

Without using the getProtectionDomain() method, how could I print the parent of a class?

For example

class Hi {
    public static void main(String[] args) {
        // Hi.class. How can I retrieve the parent of Hi.class?
    }
}
Boann
  • 48,794
  • 16
  • 117
  • 146
Samuel Musa
  • 68
  • 2
  • 11

3 Answers3

1

You can do:

Hi.class.getSuperclass();

To get the parent class of the class that your method currently resides in.

If you want something else, please describe what it is you want.

RutledgePaulV
  • 2,568
  • 3
  • 24
  • 47
0

In your code you din't inherit any class. So, by default in java every class inherits java.lang.Object class.

for that you can use Hi.class.getSuperclass()

Manoj Kumar
  • 745
  • 2
  • 8
  • 29
0

You can use getSuperclass() api

getClass().getSuperclass()

But don't use this. It is certainly a sign of bad design.

It is copied from, For details read

Community
  • 1
  • 1
atish shimpi
  • 4,873
  • 2
  • 32
  • 50
  • At least cite your sources: http://stackoverflow.com/questions/3294656/how-to-get-the-parent-base-class-object-super-getclass – Kuba Spatny Jan 10 '15 at 18:59