O'Reilly logo

Special Edition Using Java 2 Standard Edition by Geoff Friesen, Chuck Cavaness, Brian Keeton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Object Class

The java.lang.Object class sits at the root of the Java class hierarchy and is therefore a superclass of every class you create. Object is unique in that it is the only class in Java without a superclass. The methods implemented by Object provide a framework for several general-purpose operations. You saw one of these methods, the toString() method, earlier in the StopLightColor class (refer to Listing 7.5). You can override toString() in the classes you declare to define a text representation of a class instance. Whenever your program has a need to display a value for an object, toString() is called to find out what to display. This is how a method such as System.out.println() can accept an Object as a parameter in place of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required