Java Object Reference Parameters
Consider the following 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 by adding the following mutator method:
public void addYears(int n) // add n years to date
Here is part of a poorly coded client program that uses the Date class:
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 will be true after executing this code?
A
The oldDate object remains unchanged.
B
recentDate refers to the same object as oldDate.
C
recentDate is a null reference.
D
A NullPointerException is thrown.
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE