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,711–1,720 of 2,811
  1. 1711
  2. 1712
  3. 1713
  4. 1714
  5. 1715
  6. 1716
  7. 1717
  8. 1718
  9. 1719
  10. 1720

Question 1711

Multiple choice Unit 3: Class Creation
Consider the following class. public class ScoreCard { private int score; public ScoreCard() { this(10); } public ScoreCard(int s) { score = s; } public int…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1712

Multiple choice Unit 3: Class Creation
Consider the following class. public class Wallet { private int dollars; public Wallet(int d) { dollars = d; } public int spend(int amount) { if (amount <=…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1713

Multiple choice Unit 3: Class Creation
Consider the following class. public class Clock { private int hour; public Clock(int h) { hour = h; } public void advance() { hour++; if (hour == 24) hour = 0;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1714

Multiple choice Unit 3: Class Creation
Consider the following class definition. public class Badge { private static int next = 1; private int id; public Badge() { id = next; next = next + 2; } public…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1715

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

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1716

Multiple choice Unit 3: Class Creation
Consider the following class.
public class Lamp
{
    private boolean on;

    public Lamp(boolean start)
    {
        on = start;
    }

    public void toggle()
    {
        on = !on;
    }

    public boolean isOn()
    {
        return on;
    }
}
Assume the following code segment appears in another class.
Lamp a = new Lamp(true);
Lamp b = a;
b.toggle();
Lamp c = new Lamp(true);
c.toggle();
System.out.println(a.isOn() + " " + c.isOn());
What is printed?
Pick an answer, then check it. The solution opens in a window.

Question 1717

Multiple choice Unit 3: Class Creation
Consider the following class. public class Pair { private int left; private int right; public Pair(int l, int r) { left = l; right = r; } public void shift() {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1718

Multiple choice Unit 3: Class Creation
Consider the following class. public class Record { private int score; private String label; } Assume no constructor…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1719

Multiple choice Unit 3: Class Creation
Consider the following class.
public class Seat
{
    private static int num = 10;
    private int id;

    public Seat()
    {
        num++;
        id = num;
    }

    public int getId()
    {
        return id;
    }
}
If two Seat objects are constructed, what IDs do they receive, in order?
Pick an answer, then check it. The solution opens in a window.

Question 1720

Multiple choice Unit 3: Class Creation
Consider the following class.
public class SwitchBox
{
    private boolean on;

    public SwitchBox(boolean start)
    {
        on = start;
    }

    public boolean flip()
    {
        boolean old = on;
        on = !on;
        return old;
    }

    public boolean isOn()
    {
        return on;
    }
}
Assume the following code segment appears in another class.
SwitchBox b = new SwitchBox(false);
System.out.println(b.flip() + " " + b.isOn());
What is printed?
Pick an answer, then check it. The solution opens in a window.
Question 1,711 of 2,811
Page 172 of 282