Home Quizzes Quiz Detail
Practice Quiz

AP Computer Science Unit 2 - Practice Questions

20 questions 5.0 rating Mobile friendly
$69.00

Unlock the full practice quiz

Get complete access to the questions, explanations and printable quiz resources.

Full access: unlock all quiz questions and explanations.
Printable review: access the full quiz PDF with correct answers after purchase.

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.

Sample Questions

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?
Rational rat = new Rational(numer, denom); rat.reduce(); return rat;
I and II only
III only
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?
the reduce() method is not intended for use by clients of the Rational class.
hrs = h; mins = m; secs = s;
recentDate is a null reference.
I only
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);
I only
Rational rat = new Rational(numer, denom); rat.reduce(); return rat;
III only
Two overloaded methods in the same class must have parameters with different names.
Explanation:
Correct answer: III only
Question 4
Which statement about parameters is false?
III only
I only
Two overloaded methods in the same class must have parameters with different names.
the reduce() method is not intended for use by clients of the Rational class.
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?
Rational r4 = new Rational(3.5);
Date d = new Date(2, 13, 1947);
t1, t2, t3, and t4 all represent the identical temperature, in degrees Fahrenheit.
9 27 6 3
Explanation:
Correct answer: Date d = new Date(2, 13, 1947);

Ready to test your knowledge?

Buy Now to Access

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.

Frequently Asked Questions

This quiz contains a total of 20 practice questions carefully selected to test your knowledge on this subject.
Yes, you will have exactly 0 minutes to complete the exam. A countdown timer will be visible once you start.
Yes, you can retake this practice test as many times as you need. The questions and options may be randomized on subsequent attempts to ensure comprehensive learning.

Reviews

5.0

Based on 0 reviews

Leave a Review

No reviews yet. Be the first to review!