Java Reference
In-Depth Information
overrides it so that the string containing the time in the form hh:mm:ss is returned.
Similarly, the class Person also overrides it.
The method equals is also a very useful method of the class Object . This method's
definition, as given in the class Object , determines whether the object invoking this
method and the object passed as a parameter refer to the same memory space, that is, whether
they point to data in the same memory space. The method equals determines whether the
two objects are aliases. As in the case of the method toString , to implement its own needs,
every user-defined class also usually overrides the method equals . For example, in the
class Clock , in Chapter 8, the method equals was overridden to determine whether the
instance variables ( hr , min ,and sec )oftwo Clock objects contained the same value. (You
may review the definition of the method equals of the class Clock to see how this
method may be written for a class.)
As usual, the default constructor is used to initialize an object. The method clone makes
a copy of the object and returns a reference to the copy. However, the method clone
makes only a memberwise (that is, field-by-field) copy of the object. In other words, the
method clone provides a shallow copy of the data.
Java Stream Classes
In Chapter 2, we used the class Scanner for inputting data from the standard input
device. Chapter 3 described in detail how to perform input/output (I/O) using Java
stream classes, such as FileReader and PrintWriter . In Java, stream classes are
implemented using the inheritance mechanism, as shown in Figure 10-6.
1
0
Object
Scanner
Reader
InputStreamReader
FileReader
Writer
PrintWriter
FIGURE 10-6 Java stream classes hierarchy
 
Search WWH ::




Custom Search