| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
About Exam
hard Solved by 1 students
Java Object Reference Parameters
< Prev
Next >

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.

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.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy