9.7. Object Class

As we discussed earlier in this chapter, all classes in Java inherit directly or indirectly from the Object class (package java.lang), so its 11 methods are inherited by all other classes. Figure 9.18 summarizes Object’s methods.

Figure 9.18. Object methods that are inherited directly or indirectly by all classes.
MethodDescription
cloneThis protected method, which takes no arguments and returns an Object reference, makes a copy of the object on which it is called. When cloning is required for objects of a class, the class should override method clone as a public method and should implement interface Cloneable (package java.lang). The default implementation of this method performs a so-called shallow copy—instance variable values ...

Get Java™ How to Program, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.