| preferred AP College board partner for AP classes
easy Solved by 2 students
Object Instantiation and Initialization
< Prev
Next >

Consider the following Date class and a client class BirthdayStuff that uses it.

public class Date
{
    private int day;
    private int month;
    private int year;

    public Date(int mo, int da, int yr)
    {
        /* implementation not shown */
    }

    public int month() // returns month of Date
    {
        /* implementation not shown */
    }

    public int day() // returns day of Date
    {
        /* implementation not shown */
    }

    public int year() // returns year of Date
    {
        /* implementation not shown */
    }

    // Other methods not shown
}
public class BirthdayStuff
{
    public static Date findBirthdate()
    {
        /* code to get birthDate */
        return birthDate;
    }

    public static void main(String[] args)
    {
        Date d = findBirthdate();
        /* ... */
    }
}

Which of the following code segments is a valid replacement for /* code to get birthDate */ in the findBirthdate method? Assume that where indicated, user input is correctly read and stored.

I.

System.out.println("Enter birthdate: mo, day, yr: ");
int m = ...; // reads user input
int d = ...; // reads user input
int y = ...; // reads user input
Date birthDate = new Date(m, d, y);

II.

System.out.println("Enter birthdate: mo, day, yr: ");
// read user input
// read user input
// read user input
int birthDate.month() = ...;
int birthDate.day() = ...;
int birthDate.year() = ...;
Date birthDate = new Date(birthDate.month(), birthDate.day(), birthDate.year());

III.

System.out.println("Enter birthdate: mo, day, yr: ");
// read user input
// read user input
// read user input
int birthDate.month = ...;
int birthDate.day = ...;
int birthDate.year = ...;
Date birthDate = new Date(birthDate.month, birthDate.day, birthDate.year);
A

III only

B

II only

C

I only

D

I and II only

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1kaisuki11 0m 00s 100
#2ravi.palepu01 3m 14s -204
#3y.seong202724 16m 53s -833
APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy