Why super.getClass () in a subclass returns the name of the subclass

I am inside a subclass, and when I try to find the name of the superclass, I tried super.getClass (), but it only returns the name of the subclass to me. Why?

+7
source share
3 answers

getClass().getSuperclass() .

+8
source

If you override a method from your superclass (or superclass of a superclass, etc.), super.theMethod() will refer to the original method, and not to the one with which you redefined it. If you have not performed the actual redefinition of theMethod , super.theMethod() will act exactly like theMethod() .

In this case, I assume that you did not redefine getClass() (in fact, I know that you did not do this because it is final), so super.getClass() acts exactly like getClass() , i.e. in any case, the getClass method The Object class is called.

+4
source

This is because you are creating an object of a derived class, not a superclass .. you can try this

 this.getClass().getSuperClass(); 
0
source

All Articles