Verityprep
Question Bank · Unit 3

AP® Computer Science A Class Creation Multiple Choice Questions

Work through AP Computer Science A multiple-choice questions on Class Creation, 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 311–320 of 359
  1. 311
  2. 312
  3. 313
  4. 314
  5. 315
  6. 316
  7. 317
  8. 318
  9. 319
  10. 320

Question 311

Multiple choice Writing Classes
Consider the following class. public class Point { private int x; private int y; public Point(int a, int b) { x = a; y = b; } public void shift(int d) { x = x +…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 312

Multiple choice Writing Classes
Consider the following class.
public class Stamp
{
    private String code;

    public Stamp(String c) { code = c; }
    public String toString() { return "[" + code + "]"; }
}
Consider the following code segment.
Stamp s = new Stamp("A17");
System.out.println("mail " + s);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 313

Multiple choice Writing Classes
Consider the following method. public static void modify(int n) { n = n + 100; } The following code segment appears in…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 314

Multiple choice Writing Classes
Consider the following class.
public class Basket
{
    private int[] items;

    public Basket(int[] arr) { items = arr; }
    public void zeroFirst()      { items[0] = 0; }
    public int firstItem()       { return items[0]; }
}
Consider the following code segment.
int[] data = {7, 8, 9};
Basket b = new Basket(data);
b.zeroFirst();
System.out.println(data[0] + " " + b.firstItem());
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 315

Multiple choice Writing Classes
Consider the following methods, which appear in the same class. public static int apply(int n) { return n * 2; } public static double apply(double n)…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 316

Multiple choice Writing Classes
Consider the following class. public class Pair { private int x; private int y; public Pair(int x, int y) { x = x; y = y; } public int getX() { return x; }…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 317

Multiple choice Writing Classes
Consider the following class. public class Box { private String label; public Box(String s) { label = s; } public int labelLength() { return…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 318

Multiple choice Writing Classes
Consider the following class. public class Account { private int balance; public Account(int b) { balance = b; } public int withdraw(int amount) { if (amount >…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 319

Multiple choice Writing Classes
Consider the following method. public static void addAll(ArrayList<Integer> list) { list.add(99); list = new ArrayList<Integer>(); list.add(7); } Consider the…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 320

Multiple choice Writing Classes
Consider the following class. public class Counter { private static int total = 0; private int value; public Counter() { value = 1; total = total + value; }…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 311 of 359
Page 32 of 36