Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
About Exam
hard

Java Object Reference Parameters

Mark
< Prev
Next >

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.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|