Java Reference
In-Depth Information
Display 5.20
The Class Date (Partial Dei nition) (part 2 of 2)
39 System.out.println("Fatal Error");
40 System.exit(0);
41 }
42 else
43 this .year = year;
44 }
45 public String toString()
46 ...
47 public boolean equals(Date otherDate)
48 ....
49 /**
50 Returns true if the calling object date is before otherDate (in time).
The complete definition of equals is
given later in this chapter in the
answer to Self-Test
Exercise 37, and is a
better version than the
one given in Chapter 4.
51 */
52 public boolean precedes(Date otherDate)
53 ...
54 private boolean dateOK(String monthString, int dayInt, int yearInt)
55 ...
These methods have the obvious meanings. If you need to see a full definition,
see Display 4.11 in Chapter 4 and Self-Test Exercise 37 later in this chapter.
56 }
Self-Test Exercises
36. What is the difference between the following two pieces of code? The fi rst piece
appears in Display 5.21 .
Person adams =
new Person("John Adams",
new Date("February", 15, 1947), null );
//Second piece is below:
Date theDate = new Date("February", 15, 1947);
Person adams = new Person("John Adams", theDate, null );
37. When we defi ned the class Date in Chapter 4 (Display 4.11), we had not yet
discussed null . So, the defi nition of equals given there did not account for the
possibility that the argument could be null . Rewrite the defi nition of equals for
the class Date to account for the possibility that the argument might be null .
 
 
Search WWH ::




Custom Search