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 321–330 of 359
  1. 321
  2. 322
  3. 323
  4. 324
  5. 325
  6. 326
  7. 327
  8. 328
  9. 329
  10. 330

Question 321

Multiple choice Writing Classes
Consider the following class. public class Box { private int value; public Box(int v) { value = v; } public int get() { return value; } public void set(int v) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 322

Multiple choice Writing Classes
Consider the following class. public class Counter { private int n; public Counter() { n = 0; } public int bump() { n = n + 1; return n; } public int get() {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 323

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

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 324

Multiple choice Writing Classes
Consider the following class.
public class Account
{
    private int id;
    private double balance;
    private boolean active;
    private String owner;

    public Account(int theId)
    {
        id = theId;
    }

    public String describe()
    {
        return id + " " + balance + " " + active + " " + owner;
    }
}
Consider the following code segment.
Account a = new Account(42);
System.out.println(a.describe());
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 325

Multiple choice Writing Classes
Consider the following class. public class Token { private static int issued = 0; private int id; public Token() { issued = issued + 1; id = issued; } public…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 326

Multiple choice Writing Classes
Consider the following class. public class Pet { private String name; private int age; public Pet(String name, int age) { name = name; this.age = age; } public…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 327

Multiple choice Writing Classes
A programmer is designing a class Score intended to represent a numeric grade with both an int form and a double form. Consider the four method declarations…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 328

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

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

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