Class SimpleDate encapsulates integer instance variables month, day and year. Co
ID: 3570671 • Letter: C
Question
Class SimpleDate encapsulates integer instance variables month, day and year. Consider the following equals method in class SimpleDate:
public boolean equals( Object o )
{
if ( !( d instanceof SimpleDate ) )
return false;
( Insert appropriate code from selections below)
if ( month == d1.month
&& day == d1.day
&& year == d1.year )
return true;
else
return false;
}
Which statement(s) could be used to complete the above method body code correctly?
SimpleDate d1;
d1 = (SimpleDate)o;
SimpleDate d1 = o;
SimpleDate d1 = (SimpleDate)o;
Both a and c
a.SimpleDate d1;
d1 = (SimpleDate)o;
SimpleDate d1 = o;
c.SimpleDate d1 = (SimpleDate)o;
d.Both a and c
Explanation / Answer
Correct answer is d. Both a and c
Explanation:
The defintion of SimpleDate class:
//Create a SimpleDate class's objects d1 and o.
SimpleDate d1;
d1 = (SimpleDate)o;
(or)
//Create a SimpleDate class's objects d1 and o.
SimpleDate d1 = (SimpleDate)o;