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,721–1,730 of 2,811
  1. 1721
  2. 1722
  3. 1723
  4. 1724
  5. 1725
  6. 1726
  7. 1727
  8. 1728
  9. 1729
  10. 1730

Question 1721

Multiple choice Unit 3: Class Creation
Consider the following class.
public class Tag
{
    private String text;

    public Tag(String t)
    {
        text = t;
    }

    public void add(String s)
    {
        text = text + s;
    }

    public String show()
    {
        return text;
    }
}
Assume the following code segment appears in another class.
Tag x = new Tag("AP");
Tag y = new Tag("C");
y = x;
x.add("CSA");
System.out.println(x.show() + " " + y.show());
What is printed?
Pick an answer, then check it. The solution opens in a window.

Question 1722

Multiple choice Unit 3: Class Creation
Consider the following class. public class ScoreBoard { private int wins; public ScoreBoard() { wins = 0; } public void recordWin() { wins++; } public void…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1723

Multiple choice Unit 3: Class Creation
Consider the following class. public class Bank { private int balance; public Bank(int b) { balance = b; } public int update(int amount) { int old = balance;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1724

Multiple choice Unit 3: Class Creation

Consider the following method.

public static void adjust(int[] data, int n)
{
    data[n] = data[0] + n;
    n = n + 1;
    data[0] = data[n - 1];
}

What is printed by the following code?

int[] vals = {3, 5, 7, 9};
int k = 2;
adjust(vals, k);
System.out.println(vals[0] + " " + vals[2] + " " + k);
Pick an answer, then check it. The solution opens in a window.

Question 1725

Multiple choice Unit 3: Class Creation

Consider the following class.

public class Ticket
{
    private static int next = 100;
    private int number;

    public Ticket()
    {
        number = next;
        next = next + 5;
    }

    public int getNumber()
    {
        return number;
    }

    public static int peekNext()
    {
        return next;
    }
}

What is printed by the following code?

Ticket a = new Ticket();
Ticket b = new Ticket();
System.out.println(a.getNumber() + " " + b.getNumber() + " " + Ticket.peekNext());
Pick an answer, then check it. The solution opens in a window.

Question 1726

Multiple choice Unit 3: Class Creation

Consider the following class.

public class Counter
{
    private int value;

    public Counter(int v)
    {
        value = v;
    }

    public int bump(int n)
    {
        value = value + n;
        return value;
    }

    public int read()
    {
        return value;
    }
}

What is printed by the following code?

Counter c = new Counter(3);
int a = c.bump(2);
int b = c.bump(a - 1);
System.out.println(a + " " + b + " " + c.read());
Pick an answer, then check it. The solution opens in a window.

Question 1727

Multiple choice Unit 3: Class Creation
Consider the following method. public static int calc(int a, int b) { if (a > b) { a = a - b; }…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1728

Multiple choice Unit 3: Class Creation

Consider the following class.

public class Box
{
    private int value;

    public Box(int v)
    {
        value = v;
    }

    public int add(int n)
    {
        int old = value;
        value = value + n;
        return old;
    }

    public int get()
    {
        return value;
    }
}

What is printed by the following code?

Box p = new Box(4);
Box q = p;
int x = q.add(3);
p.add(x);
System.out.println(q.get());
Pick an answer, then check it. The solution opens in a window.

Question 1729

Multiple choice Unit 3: Class Creation

Consider the following method.

public static void change(int[] a)
{
    a[1] = a[0] + a[2];
    a = new int[3];
    a[0] = 1;
}

What is printed by the following code?

int[] data = {2, 4, 6};
change(data);
System.out.println(data[0] + " " + data[1] + " " + data[2]);
Pick an answer, then check it. The solution opens in a window.

Question 1730

Multiple choice Unit 3: Class Creation
Consider the following class. public class Log { private static int total = 0; private int local; public Log() { local = total; total++; } public int bump() {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1,721 of 2,811
Page 173 of 282