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?
}
}
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?
}
}
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.
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()
You can use getSuperclass()
api
getClass().getSuperclass()
But don't use this. It is certainly a sign of bad design.