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 301–310 of 359
  1. 301
  2. 302
  3. 303
  4. 304
  5. 305
  6. 306
  7. 307
  8. 308
  9. 309
  10. 310

Question 301

Multiple choice Writing Classes
Consider the following class.
public class Node
{
    private String label;
    public Node(String l) { label = l; }
    public String getLabel() { return label; }
}
Consider the following code segment.
Node n = new Node("start");
Node m = null;
m = n;
n = new Node("mid");
System.out.println(n.getLabel() + " " + m.getLabel());
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 302

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 303

Multiple choice Writing Classes
Consider the following class. public class Printer { public void show(int x) { System.out.print("int "); } public void show(double x) { System.out.print("double…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 304

Multiple choice Writing Classes
Consider the following class.
public class Coord
{
    private int x;
    private int y;
    public Coord(int x, int y) { this.x = x; this.y = y; }
    public String toString() { return "(" + x + "," + y + ")"; }
}
Consider the following code segment.
Coord c = new Coord(3, 4);
System.out.println("at " + c);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 305

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

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 306

Multiple choice Writing Classes
Consider the following class. public class Bag { private int count; public Bag(int c) { count = c; } public int getCount() { return count; } public void…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 307

Multiple choice Writing Classes
Consider the following class. public class Player { private static int totalGames = 0; private int wins; public Player() { wins = 0; } public void…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 308

Multiple choice Writing Classes
Consider the following class. public class Tag { private String text; public Tag(String t) { text = t; } public String getText() { return text; } } Consider the…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 309

Multiple choice Writing Classes
Consider the following class. public class Counter { private int value; public Counter(int start) { value = start; } public Counter() { this(10); } public void…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 310

Multiple choice Writing Classes
Consider the following class. public class Ticket { private static int nextId = 100; private int id; public Ticket() { id = nextId; nextId = nextId + 10; }…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 301 of 359
Page 31 of 36