| preferred AP College board partner for AP classes
medium Solved by 6 students
Client Class Method Implementation
< Prev
Next >

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

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1dinhhoa12 0m 00s 90
#2sailajavadlamani3314 0m 00s 70
#3Ishaan.m.kurup15 0m 00s 60
#4y.seong202701 2m 25s -155
#5songqiuhui201201 3m 07s -197
#6psak1202 3m 33s -233
#7suhanakochhar00614 10m 15s -545
APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy