| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
About Exam
medium Solved by 9 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

III only

C

II only

D

I only

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

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
#7varunrajaram101 3m 47s -237
#8bommasam00026 9m 17s -397
#9suhanakochhar00614 10m 15s -545
Items per page:
10
1 – 9 of 9
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy