It does not return the name of the class - it returns Classrepresenting this type of object. Each object “knows” what type it really is — how castes can work or fail depending on the type of runtime. Object.getClass()just retrieves the relevant information from the object.
If you have a class that contains only one int, each object will still occupy more than 4 bytes in memory: there actually is a "header" of the object containing things such as a link to the actual type of the object, information to do with the monitor associated with this object, etc.
source
share