Object Instantiation and Initialization
Which of the following is a correct replacement for /* code to get birthDate */?
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()
{
...
}
}
Here is a client program that uses Date objects:
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 is a correct replacement for /* code to get birthDate */?
I.
System.out.println("Enter birthdate: mo, day, yr: ");
int m = ...;
int d = ...;
int y = ...;
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 and II only
D
I only
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | kaisuki | 1 | 1 | 0m 00s | 100 |
| #2 | ravi.palepu | 0 | 1 | 3m 14s | -204 |
| #3 | y.seong2027 | 2 | 4 | 16m 53s | -833 |
| #4 | bommasam000 | 4 | 13 | 25m 58s | -1,248 |
Items per page:
10
1 – 4 of 4
