So, here is a surprise. Each Java class, by default (without an explicit declaration), extends the class Object. To be precise, it is java.lang.Object, but we have not introduced packages yet and will only be talking about them in Chapter 7, Packages and Accessibility (Visibility).
All Java objects inherit all the methods from it. There are ten of them:
- public boolean equals (Object obj)
- public int hashCode()
- public Class getClass()
- public String toString()
- protected Object clone()
- public void wait()
- public void wait(long timeout)
- public void wait(long timeout, int nanos)
- public void notify()
- public void notifyAll()
Let's briefly visit each of these methods.
Before we do that, we would like to mention that you can override their default behavior in your classes, and re-implement them any way you need, which programmers often do. We will explain how to do this in Chapter 6, Interfaces, Classes, and Objects Construction.