The getClass() method is defined in java.lang.Object and, therefore, can be called by any reference to the object.
It gets the class object associated with the runtime type of the object to which the reference points belong.,
The getClass () method is actually not like .class. Closer is a Class.forName (String) that receives a class object for a class called String.
In situations where they can be used, use .class as it is more efficient.
source share