Verityprep
Question Bank

AP® Computer Science A Multiple Choice Questions

Work through AP Computer Science A multiple-choice questions unit by unit, then check each answer against a worked solution.

Free · no sign-up Open questions need no account. Sign up or log in to open the rest.

Questions 1,701–1,710 of 2,811
  1. 1701
  2. 1702
  3. 1703
  4. 1704
  5. 1705
  6. 1706
  7. 1707
  8. 1708
  9. 1709
  10. 1710

Question 1701

Multiple choice Unit 3: Class Creation
Consider the following class.
public class Money
{
    private int cents;

    public Money(int c) { cents = c; }
    public String toString()
    {
        return "$" + (cents / 100) + "." + (cents % 100);
    }
}
Consider the following code segment.
Money m = new Money(2507);
System.out.println("price: " + m);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 1702

Multiple choice Unit 3: Class Creation
Consider the following class. public class Bag { private int items; public Bag(int n) { items = n; } public int getItems() { return items; } public void add(int…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1703

Multiple choice Unit 3: Class Creation
Consider the following two classes, written in the same package. public class Wallet { private int coins; public Wallet(int c) { coins = c; } public int…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1704

Multiple choice Unit 3: Class Creation
Consider the following class. public class Snapshot { private int[] values; public Snapshot(int[] data) { values = data; } public int at(int i) { return…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1705

Multiple choice Unit 3: Class Creation
Consider the following class.
public class Stat
{
    private int total;
    private int count;

    public Stat() { total = 0; count = 0; }

    public void record(int v)
    {
        total = total + v;
        count = count + 1;
    }

    public double mean()
    {
        if (count == 0) { return 0.0; }
        return total * 1.0 / count;
    }

    public void reset() { total = 0; count = 0; }
}
Consider the following code segment.
Stat s = new Stat();
s.record(2);
s.record(4);
double a = s.mean();
s.reset();
s.record(10);
double b = s.mean();
System.out.println(a + " " + b);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 1706

Multiple choice Unit 3: Class Creation
Suppose secret is declared private in class…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1707

Multiple choice Unit 3: Class Creation
Consider the following class. public class Box { private int value; public Box(int v) { value = v; } public void add(int n) { value = value + n; } public int…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1708

Multiple choice Unit 3: Class Creation
Consider the following class. public class Pair { private int x; private int y; public Pair(int a, int b) { x = a; y = b; } public Pair swapped() { return new…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1709

Multiple choice Unit 3: Class Creation
Consider the following class. public class Record { private int score; private String name; private boolean active; }…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1710

Multiple choice Unit 3: Class Creation
Consider the following class. public class Marker { private static int next = 100; private int id; public Marker() { id = next;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1,701 of 2,811
Page 171 of 282