Using super. in super class | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Using super. in super class

Hey, i understand that using super in subclass refers to it's super class but then if you use super in super class why does it seem to refer to its self and not ObjectClass or is it?? When calling super.getClass().getName(); in super class it returns my superclass and not ObjectClass which I was expecting? I have searched about but only find what super means in sub class 😅 thanks

12th Sep 2019, 4:22 PM
D_Stark
D_Stark - avatar
3 Answers
+ 4
Denise Roßberg Perfect! super.getName().getSuperclass(); got me what I needed 👍👍👍
13th Sep 2019, 8:28 AM
D_Stark
D_Stark - avatar
+ 3
Very interesting question. I have found this article about calling super(): https://stackoverflow.com/questions/12066984/java-does-object-class-have-a-constructor The object class has a constructor but I think it is not possible to show it on sololearn that you are really calling the constructor of the object class. About calling super.getClass().getName(): I need more time for research. I can not explain why it prints the name of the current class and not of object class.
12th Sep 2019, 10:24 PM
Denise Roßberg
Denise Roßberg - avatar