Client Class Method Implementation
Consider the following Time class definition.
public class Time
{
private int hrs;
private int mins;
private int secs;
public Time()
{ /* implementation not shown */ }
public Time(int h, int m, int s)
{ /* implementation not shown */ }
/** Resets time to hrs = h, mins = m, secs = s. */
public void resetTime(int h, int m, int s)
{ /* implementation not shown */ }
/** Advances time by one second. */
public void increment()
{ /* implementation not shown */ }
/** Returns true if this time equals t, false otherwise. */
public boolean equals(Time t)
{ /* implementation not shown */ }
/** Returns true if this time is earlier than t, false otherwise. */
public boolean lessThan(Time t)
{ /* implementation not shown */ }
/** Returns a String with the time in the form hrs:mins:secs. */
public String toString()
{ /* implementation not shown */ }
}
The following display method is part of a client class and is intended to print the time represented by its parameter t.
/** Outputs time t in the form hrs:mins:secs. */
public void display(Time t)
{
/* method body */
}
Which of the following code segments, if used to replace /* method body */, will correctly implement the display method?
I.
Time T = new Time(h, m, s);
System.out.println(T);
II.
System.out.println(t.hrs + ":" + t.mins + ":" + t.secs);
III.
System.out.println(t);
A
II and III only
B
I only
C
III only
D
II only
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | dinhhoa | 1 | 2 | 0m 00s | 90 |
| #2 | sailajavadlamani33 | 1 | 4 | 0m 00s | 70 |
| #3 | Ishaan.m.kurup | 1 | 5 | 0m 00s | 60 |
| #4 | y.seong2027 | 0 | 1 | 2m 25s | -155 |
| #5 | songqiuhui2012 | 0 | 1 | 3m 07s | -197 |
| #6 | psak12 | 0 | 2 | 3m 33s | -233 |
| #7 | suhanakochhar006 | 1 | 4 | 10m 15s | -545 |
APFIVE