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.

Subtopic: Writing Classes Clear filter

Questions 331–340 of 359
  1. 331
  2. 332
  3. 333
  4. 334
  5. 335
  6. 336
  7. 337
  8. 338
  9. 339
  10. 340

Question 331

Multiple choice Writing Classes
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 332

Multiple choice Writing Classes
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 333

Multiple choice Writing Classes
Suppose secret is declared private in class…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 334

Multiple choice Writing Classes
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 335

Multiple choice Writing Classes
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 336

Multiple choice Writing Classes
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 337

Multiple choice Writing Classes
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 338

Multiple choice Writing Classes
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 339

Multiple choice Writing Classes
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 340

Multiple choice Writing Classes
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 331 of 359
Page 34 of 36