Does the call to the overridden Method(), not invoke the parent class's Method(). Even though the actual call is made on the object of Child, because of the keyword super, do not we get the name of the Parent class displayed from the Child's Method().

Please clarify on this.

Mathias Nilsson

Ranch Hand

Posts: 367

posted 10 years ago

Hi! This is taken from the api

getClass public final Class getClass()Returns the runtime class of an object. That Class object is the object that is locked by static synchronized methods of the represented class.

Returns: the object of type Class that represents the runtime class of the object.

This will get you the result you are looking fpr.

SCJP1.4

Anonymous

Ranch Hand

Posts: 18944

posted 10 years ago

Thanks Mathias. But what if I need to display the name of the Parent class within a method of a Child class. Do I need to create an object of Parent class in the child object and invoke getClass().getName() method. Is there any other way of getting the desired output.