Question 1
Questions 1–3 refer to the Time class declared below: 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 */ } /** @return true if this time equals t, false otherwise */ public boolean equals(Time t) { /* implementation not shown */ } /** @return true if this time is earlier than t, false otherwise */ public boolean lessThan(Time t) { /* implementation not shown */ } /** @return a String with the time in the form hrs:mins:secs */ public String toString() { /* implementation not shown */ } } Which of the following is a false statement about the methods?
Correct Answer:
The Time class has three constructors.
Explanation:
Correct answer: The Time class has three constructors.
Question 2
Questions 1–3 refer to the Time class declared below: 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 */ } /** @return true if this time equals t, false otherwise */ public boolean equals(Time t) { /* implementation not shown */ } /** @return true if this time is earlier than t, false otherwise */ public boolean lessThan(Time t) { /* implementation not shown */ } /** @return a String with the time in the form hrs:mins:secs */ public String toString() { /* implementation not shown */ } } Which of the following represents correct implementation code for the constructor with parameters?
Correct Answer:
hrs = h; mins = m; secs = s;
Explanation:
Correct answer: hrs = h; mins = m; secs = s;
Question 3
Questions 1–3 refer to the Time class declared below: 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 */ } /** @return true if this time equals t, false otherwise */ public boolean equals(Time t) { /* implementation not shown */ } /** @return true if this time is earlier than t, false otherwise */ public boolean lessThan(Time t) { /* implementation not shown */ } /** @return a String with the time in the form hrs:mins:secs */ public String toString() { /* implementation not shown */ } } A client class has a display method that writes the time represented by its parameter: /** Outputs time t in the form hrs:mins:secs. * @param t the time */ public void display(Time t) { /* method body */ } Which of the following are correct replacements for / method body /? 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);
Correct Answer:
III only
Explanation:
Correct answer: III only
Question 4
Which statement about parameters is false?
Correct Answer:
Two overloaded methods in the same class must have parameters with different names.
Explanation:
Correct answer: Two overloaded methods in the same class must have parameters with different names.
Question 5
Questions 5–11 refer to the following Date class declaration: public class Date { private int day; private int month; private int year; public Date() //default constructor { ... } public Date(int mo, int da, int yr) //constructor { ... } 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() { ... } } Which of the following correctly constructs a Date object in a client class?
Correct Answer:
Date d = new Date(2, 13, 1947);
Explanation:
Correct answer: Date d = new Date(2, 13, 1947);
Question 1
Exam overview

About this Exam

Prepare with the AP Computer Science Unit 2 - Practice Questions practice quiz. This question bank includes 20 questions covering public, date, temperature, implementation, and shown. Use it to review important concepts, identify knowledge gaps, and build confidence for the related exam, course, or assessment.

More details

Additional Information

AP Computer Science Unit 2 - Practice Questions

This practice set contains 20 questions from the matching question bank and focuses on public, date, temperature, implementation, and shown. Work through each question carefully, review the provided solutions, and revisit topics that need more study before your next attempt.

This is an independent study resource intended for practice and review; it is not an official examination or an endorsement by any organization named in the title.

Quiz information

Frequently Asked Questions

The complete question count is available after full access is unlocked.
No fixed duration is currently configured for this quiz.
Question explanations are included where they are available in the quiz content, helping you review the reasoning after answering.
Yes. You can retake the practice test again as you continue studying during your available access period.
After your access is confirmed, you can continue into the complete practice exam from this quiz flow.
Unless explicitly stated otherwise, this page provides independent practice material for study and exam preparation and is not the official examination itself.
Keep studying

Related Questions