Java Reference
In-Depth Information
34. aVariable == null
35.
It is unlikely but it is legal. This is an example of an anonymous object, as
described in the text.
36.
The only difference is that the object of type Date is given the name theDate in
the second version. It makes no difference to the object adams .
37.
The following of equals is used in the file Date.java in the Chapter 5 directory
of the source code on the CD:
extra code
on CD
public boolean equals(Date otherDate)
{
if (otherDate == null )
return false ;
else
return ( (month.equals(otherDate.month)) &&
(day == otherDate.day) && (year == otherDate.year) );
}
38.
A copy constructor is a constructor with one parameter of the same type as the
class. A copy constructor should be designed so that the object it creates is intu-
itively an exact copy of its parameter, but a completely independent copy, that is,
a deep copy.
39.
The first piece of code produces the output:
July 4, 1776
The second piece of code produces the output:
January 1, 2006
40. Natalie Dressed, April 1, 1984-
41. public void set(String newName, Date birthDate, Date deathDate)
{
if (consistent(birthDate, deathDate))
{
name = newName;
born = new Date(birthDate);
if (deathDate == null )
died = null ;
else
died = new Date(deathDate);
}
else
{
System.out.println("Inconsistent dates. Aborting.");
System.exit(0);
}
}
Search WWH ::




Custom Search