Java Object Reference Parameters
Consider the following Date class.
public class Date
{
private int day;
private int month;
private int year;
public Date()
{
...
}
// default constructor
public Date(int mo, int da, int yr)
{
...
}
public int month() // returns month of Date
{
...
}
public int day() // returns day of Date
{
...
}
public int year() // returns year of Date
{
...
}
// Returns String representation of Date as "m/d/y", e.g., 4/18/1985.
public String toString()
{
...
}
}
The Date class is modified to include the following mutator method.
public void addYears(int n) // add n years to date
Now consider the following client code.
public static void addCentury(Date recent, Date old)
{
old.addYears(100);
recent = old;
}
public static void main(String[] args)
{
Date oldDate = new Date(1, 13, 1900);
Date recentDate = null;
addCentury(recentDate, oldDate);
...
}
Which of the following statements is true after the call to addCentury in the main method completes?
A
recentDate is a null reference.
B
recentDate refers to the same object as oldDate.
C
The oldDate object remains unchanged.
D
A NullPointerException is thrown.
Question Leaderboard
Not enough data yet to show leaderboard.
