What this quiz covers
This quiz focuses on Constructors, giving you a quick way to practice the rules, question types, and explanations that matter most for AP Computer Science a.
In the BankAccount code below, how does constructor chaining work in this example?
public class BankAccount {
private String accountNumber;
private double balance;
// Public default constructor: creates an account with a default balance of 0.0
public BankAccount() {
this("000000", 0.0); // Chain to the parameterized constructor
}
// Public parameterized constructor: initializes both fields from arguments
public BankAccount(String accountNumber, double balance) {
this.accountNumber = accountNumber;
this.balance = balance;
}
// Private constructor: internal helper for creating a "closed" account
private BankAccount(String accountNumber) {
this(accountNumber, 0.0); // Chain to the parameterized constructor
}
}
AP Computer Science a Quiz
Practice Constructors in AP Computer Science a with focused quiz questions that help you check what you know, review explanations, and build confidence with test-style prompts.
This quiz focuses on Constructors, giving you a quick way to practice the rules, question types, and explanations that matter most for AP Computer Science a.
Try each quiz question before looking at the correct answer. Use the explanations to review missed ideas, then come back to similar questions until the pattern feels familiar.
In the BankAccount code below, how does constructor chaining work in this example?
public class BankAccount {
private String accountNumber;
private double balance;
// Public default constructor: creates an account with a default balance of 0.0
public BankAccount() {
this("000000", 0.0); // Chain to the parameterized constructor
}
// Public parameterized constructor: initializes both fields from arguments
public BankAccount(String accountNumber, double balance) {
this.accountNumber = accountNumber;
this.balance = balance;
}
// Private constructor: internal helper for creating a "closed" account
private BankAccount(String accountNumber) {
this(accountNumber, 0.0); // Chain to the parameterized constructor
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on constructor chaining and the this() keyword. Constructor chaining in Java allows one constructor to call another constructor in the same class using this(...), which must be the first statement in the constructor. In the provided BankAccount code, the default constructor uses this("000000", 0.0) to call the two-parameter constructor, passing default values for account number and balance. Choice B is correct because it accurately describes how the default constructor chains to the parameterized constructor using this(...). Choice A is incorrect because constructors cannot call themselves recursively - this would cause infinite recursion. To help students: Emphasize that this(...) must be the first line in a constructor and demonstrate tracing through constructor chains step by step. Watch for: confusion between this() for constructor chaining and this keyword for instance references.
In the Car code below, which constructor will be invoked when creating a new instance with no arguments?
public class Car {
private String make;
private String model;
private int year;
// Public default constructor: sets year to the current year
public Car() {
this("Unknown", "Unknown", 2026); // Chain to parameterized constructor
}
// Public parameterized constructor: initializes all fields
public Car(String make, String model, int year) {
this.make = make;
this.model = model;
this.year = year;
}
// Private constructor: internal helper for creating a placeholder car
private Car(String make, String model) {
this(make, model, 2026); // Chain to parameterized constructor
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on constructor invocation and method signatures. When creating an object with new Car(), Java looks for a constructor that matches the provided arguments - in this case, no arguments means it searches for a no-argument constructor. In the provided Car code, there is a public no-argument constructor that chains to the three-parameter constructor with default values. Choice C is correct because new Car() invokes the public no-argument constructor, which then chains to the parameterized constructor. Choice B is incorrect because while the three-parameter constructor eventually runs due to chaining, it's not directly invoked - the no-argument constructor is invoked first. To help students: Use diagrams showing the flow of constructor calls and emphasize matching constructor signatures to arguments. Watch for: students confusing which constructor is initially invoked versus which constructors run due to chaining.
Refer to the Car class code below: what is the purpose of the private Car(String, String, int) constructor?
public class Car {
private String make;
private String model;
private int year;
// Public default constructor: uses placeholder values.
public Car() {
this("Unknown", "Unknown");
}
// Public parameterized constructor: supplies a default year.
public Car(String make, String model) {
this(make, model, 2026);
}
// Private full constructor: centralizes initialization in one place.
private Car(String make, String model, int year) {
this.make = make;
this.model = model;
this.year = year;
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on the purpose of private constructors in design patterns (AP CSA standard). Private constructors serve specific design purposes - they cannot be called directly from outside the class but can be used internally for constructor chaining. This pattern centralizes initialization logic in one place, reducing code duplication and ensuring consistency. In the Car class, the private Car(String, String, int) constructor contains all field initialization logic, and both public constructors chain to it. This ensures all Car objects are initialized through the same code path. Choice A is correct because the private constructor centralizes all field initialization, allowing other constructors to reuse this logic through chaining. Choice B is incorrect because private constructors cannot be called from outside the class. To help students: Explain the benefits of centralized initialization. Show how private constructors support the DRY principle. Practice identifying when to use private constructors. Watch for: misunderstanding private access, not recognizing the code reuse pattern.
Refer to the Car class code below: which constructor will be invoked when creating a new Car with no arguments?
public class Car {
private String make;
private String model;
private int year;
// Public default constructor: sets a reasonable default year.
public Car() {
this("Unknown", "Unknown"); // Constructor chaining to reuse initialization
}
// Public parameterized constructor: sets make and model, and uses current year.
public Car(String make, String model) {
this(make, model, 2026); // Constructor chaining to set all fields
}
// Private full constructor: centralizes all field initialization.
private Car(String make, String model, int year) {
this.make = make;
this.model = model;
this.year = year;
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on constructor invocation and chaining (AP CSA standard). Constructors in Java are special methods used to initialize objects when they are created. They have the same name as the class and no return type. Constructor chaining allows one constructor to call another using this() to reuse initialization logic. In the provided Car class, when new Car() is called with no arguments, the public Car() constructor is invoked. This constructor immediately chains to Car(String, String) using this("Unknown", "Unknown"), which then chains to the private Car(String, String, int) constructor. Choice C is correct because the public Car() constructor is the entry point for no-argument object creation. Choice A is incorrect because the private constructor cannot be directly invoked from outside the class - it's only accessible through constructor chaining. To help students: Draw diagrams showing the flow of constructor chaining. Practice tracing through constructor calls step by step. Emphasize that the first constructor called matches the arguments provided. Watch for: confusion about which constructor runs first versus which does the actual initialization.
Refer to the BankAccount class code below: what value will the field balance have after executing new BankAccount()?
public class BankAccount {
private String accountNumber;
private double balance;
// Public default constructor: sets a default account and zero balance.
public BankAccount() {
this("000000", 0.0);
}
// Public parameterized constructor: initializes both fields.
public BankAccount(String accountNumber, double balance) {
this.accountNumber = accountNumber;
this.balance = balance;
}
// Private constructor: blocks constructing with only a balance.
private BankAccount(double balanceOnly) {
this("000000", balanceOnly);
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on field initialization through constructor chaining (AP CSA standard). When constructors chain, the final constructor in the chain performs the actual field assignments. Understanding how values flow through constructor chains helps predict object state after construction. Primitive fields like double have default values but constructors typically set explicit values. In the BankAccount class, new BankAccount() invokes the default constructor, which chains to BankAccount(String, double) with arguments ("000000", 0.0). The two-parameter constructor sets balance to 0.0. Choice A is correct because the constructor chain explicitly sets balance to 0.0. Choice C is incorrect because primitive types like double cannot be null - they always have a value, and here it's explicitly set to 0.0. To help students: Trace field values through constructor execution. Emphasize the difference between primitive and reference type defaults. Practice predicting final field values after construction. Watch for: confusing primitive types with reference types regarding null, forgetting that constructors override default values.
Refer to the Student class code below: how does the parameterized constructor differ from the one-parameter constructor?
public class Student {
private String name;
private int id;
// Public constructor: sets name only and defaults id.
public Student(String name) {
this(name, 0);
}
// Public parameterized constructor: sets both name and id.
public Student(String name, int id) {
this.name = name;
this.id = id;
}
// Private constructor: blocks creating a student with no data.
private Student() {
this("Unknown", 0);
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on comparing constructor functionality and parameter handling (AP CSA standard). Different constructors in the same class provide flexibility in object initialization - some may set all fields, while others provide defaults for certain fields. Understanding these differences helps in choosing the appropriate constructor for specific needs. In the Student class, the one-parameter constructor Student(String) only accepts a name and defaults id to 0, while the two-parameter constructor Student(String, int) accepts and sets both name and id from arguments. Choice A is correct because the parameterized constructor initializes both fields using the provided arguments, giving full control over initial values. Choice C is incorrect because the two-parameter constructor uses the passed id value, not 0. To help students: Create tables comparing what each constructor sets. Show examples of when to use each constructor. Practice choosing constructors based on initialization needs. Watch for: assuming all constructors behave identically, misreading which parameters are used versus defaulted.
Refer to the Student class code below: what value will the field id have after executing new Student("Ana")?
public class Student {
private String name;
private int id;
// Public constructor: sets name only, defaults id to 0.
public Student(String name) {
this(name, 0); // Constructor chaining to reuse full initialization
}
// Public parameterized constructor: sets both name and id.
public Student(String name, int id) {
this.name = name;
this.id = id;
}
// Private default constructor: prevents creating a nameless student.
private Student() {
this("Unknown", 0);
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on constructor chaining and field initialization (AP CSA standard). Constructors initialize object fields when instances are created, and constructor chaining using this() allows code reuse between constructors. When one constructor calls another, the final constructor in the chain performs the actual field assignments. In the Student class, new Student("Ana") calls the one-parameter constructor, which chains to Student(String, int) with this("Ana", 0). The two-parameter constructor then sets name to "Ana" and id to 0. Choice A is correct because the constructor chain explicitly passes 0 as the id value. Choice B is incorrect because Java initializes int fields to 0 by default, but here the constructor explicitly sets it to 0 anyway. To help students: Trace through constructor chains step by step. Show how parameters flow through the chain. Practice predicting field values after construction. Watch for: forgetting that constructor chaining passes specific values, assuming uninitialized fields remain at Java defaults when constructors explicitly set them.
Refer to the Car class code below: what value will the field year have after executing new Car("Honda", "Civic")?
public class Car {
private String make;
private String model;
private int year;
// Public default constructor: uses placeholder make/model.
public Car() {
this("Unknown", "Unknown");
}
// Public parameterized constructor: sets make/model and defaults year.
public Car(String make, String model) {
this(make, model, 2026); // Chained to the full constructor
}
// Private full constructor: sets all fields.
private Car(String make, String model, int year) {
this.make = make;
this.model = model;
this.year = year;
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on tracing values through constructor chains (AP CSA standard). When constructors chain using this(), parameters are passed through the chain until reaching the constructor that performs actual field initialization. Understanding how values flow through constructor chains is crucial for predicting object state after construction. In the Car class, new Car("Honda", "Civic") calls the two-parameter constructor, which chains to the private three-parameter constructor with this("Honda", "Civic", 2026). The private constructor sets year to the hardcoded value 2026. Choice B is correct because the constructor chain explicitly passes 2026 as the year value to the private constructor. Choice C is incorrect because 2026 is a hardcoded literal value, not determined at runtime. To help students: Trace parameter values through each constructor call. Highlight where literal values versus parameters are used. Practice following constructor chains with different arguments. Watch for: assuming default values when constructors provide explicit ones, misunderstanding hardcoded values as dynamic.
In the Book code below, how does constructor chaining work in the provided example?
public class Book {
private String title;
private String author;
// Public default constructor: provides standard defaults
public Book() {
this("Untitled", "Unknown"); // Chain to parameterized constructor
}
// Public parameterized constructor: initializes both fields
public Book(String title, String author) {
this.title = title;
this.author = author;
}
// Private constructor: internal helper for author-only
private Book(String author) {
this("Untitled", author); // Chain to parameterized constructor
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on the this() mechanism for constructor chaining. The this(...) syntax is used to call another constructor within the same class, allowing code reuse and ensuring consistent initialization across different constructor variations. In the provided Book code, both the default constructor and the private constructor use this(...) to chain to the two-parameter constructor, passing appropriate values for title and author. Choice B is correct because it accurately describes that this(...) calls another constructor in the same class, enabling constructor chaining. Choice A is incorrect because this(...) doesn't create a new object - it delegates initialization to another constructor for the current object being created. To help students: Demonstrate the difference between this(...) for constructor chaining and new for object creation, using step-by-step execution traces. Watch for: confusion between constructor chaining within a class and inheritance-related super() calls.
In the Car code below, what value will the field year have after executing new Car()?
public class Car {
private String make;
private String model;
private int year;
// Public default constructor: uses the current year
public Car() {
this("Unknown", "Unknown", 2026); // Chain to parameterized constructor
}
// Public parameterized constructor: initializes all fields
public Car(String make, String model, int year) {
this.make = make;
this.model = model;
this.year = year;
}
// Private constructor: internal helper for known make/model
private Car(String make, String model) {
this(make, model, 2026);
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on constructor chaining and value assignment. When new Car() is executed, it invokes the no-argument constructor which immediately chains to the three-parameter constructor using this("Unknown", "Unknown", 2026). In the provided Car code, the chained call passes 2026 as the year parameter, which is then assigned to the year instance field in the three-parameter constructor. Choice B is correct because the constructor chain results in year being set to 2026, the value explicitly passed in the chaining call. Choice A is incorrect because while int fields do default to 0, the constructor explicitly sets year to 2026, overriding any default. To help students: Trace constructor execution with actual values, showing how parameters flow through the chain to field assignments. Watch for: students forgetting that explicit assignments in constructors override default field values.
Refer to the Book class code below: how does constructor chaining work in the provided example?
public class Book {
private String title;
private String author;
// Public default constructor: uses a default title.
public Book() {
this("Untitled", "Unknown"); // Calls the parameterized constructor
}
// Public parameterized constructor: sets both fields.
public Book(String title, String author) {
this.title = title;
this.author = author;
}
// Private constructor: prevents creating a book with only a title.
private Book(String title) {
this(title, "Unknown");
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on constructor chaining syntax and purpose (AP CSA standard). Constructor chaining in Java uses the this() syntax to call another constructor within the same class, allowing code reuse and centralized initialization logic. The this() call must be the first statement in a constructor and passes arguments to match another constructor's parameter list. In the Book class, the default constructor uses this("Untitled", "Unknown") to chain to the two-parameter constructor, reusing its initialization code. Choice A is correct because this() calls another constructor in the same class to reuse initialization logic. Choice B is incorrect because this() doesn't create a new object - it delegates to another constructor for the same object being constructed. To help students: Demonstrate the difference between this() and new. Show how constructor chaining reduces code duplication. Practice writing constructors that chain to others. Watch for: confusing this() with creating new objects, misunderstanding that chaining happens within the same object initialization.
In the Student code below, what value will the field id have after executing new Student("Maya")?
public class Student {
private String name;
private int id;
// Public constructor: sets both name and id
public Student(String name, int id) {
this.name = name;
this.id = id;
}
// Public constructor: sets name and defaults id to 0
public Student(String name) {
this(name, 0); // Chain to the two-parameter constructor
}
// Private constructor: internal helper for an unnamed student
private Student(int id) {
this("Unknown", id); // Chain to the two-parameter constructor
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on constructor chaining and field initialization. When new Student("Maya") is called, it invokes the one-parameter constructor which chains to the two-parameter constructor using this(name, 0). In the provided Student code, the one-parameter constructor passes "Maya" for name and 0 for id to the two-parameter constructor, which then assigns these values to the instance fields. Choice A is correct because the constructor chain results in id being set to 0, the default value passed in the chaining call. Choice B is incorrect because Java int fields default to 0, not 1, and the explicit assignment of 0 overrides any default. To help students: Trace through constructor execution step-by-step, showing how values flow through the chain. Watch for: confusion about default values versus explicitly assigned values in constructors.
Refer to the Book class code below: which constructor will be invoked when creating a new Book with no arguments?
public class Book {
private String title;
private String author;
// Public default constructor: supplies default values.
public Book() {
this("Untitled", "Unknown");
}
// Public parameterized constructor: initializes title and author.
public Book(String title, String author) {
this.title = title;
this.author = author;
}
// Private constructor: prevents creating with only an author.
private Book(String author) {
this("Untitled", author);
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on default constructor invocation (AP CSA standard). The default constructor is the no-argument constructor that provides standard initialization when no specific values are provided. In Java, when new is called without arguments, it specifically looks for and invokes a no-argument constructor. In the Book class, new Book() with no arguments invokes the public Book() constructor, which is the default constructor. This constructor chains to the two-parameter constructor with default values, but the initial entry point is the no-argument constructor. Choice C is correct because the public Book() constructor is designed to handle no-argument object creation. Choice A is incorrect because the private constructor cannot be directly called from outside the class, even though it exists. To help students: Emphasize that constructor selection is based on argument matching. Practice identifying default constructors in class definitions. Show that default constructors often chain to other constructors. Watch for: confusion about which constructor is callable based on access modifiers, misunderstanding the term 'default constructor'.
Refer to the BankAccount class code below: how does the parameterized constructor differ from the default constructor?
public class BankAccount {
private String accountNumber;
private double balance;
// Public default constructor: creates an account with a placeholder number and zero balance.
public BankAccount() {
this("000000", 0.0); // Constructor chaining to centralize initialization
}
// Public parameterized constructor: initializes account number and starting balance.
public BankAccount(String accountNumber, double balance) {
this.accountNumber = accountNumber;
this.balance = balance;
}
// Private constructor: prevents creating an account with only a balance.
private BankAccount(double balanceOnly) {
this("000000", balanceOnly);
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on parameterized versus default constructor functionality (AP CSA standard). Constructors in Java initialize object state when instances are created. Default constructors take no parameters and provide standard initialization, while parameterized constructors accept arguments to set specific initial values. In the BankAccount class, the default constructor BankAccount() chains to the parameterized constructor with default values ("000000", 0.0), while the parameterized constructor BankAccount(String, double) directly initializes both fields with provided arguments. Choice A is correct because the parameterized constructor sets both accountNumber and balance using the arguments passed to it. Choice D is incorrect because it suggests the parameterized constructor always sets balance to 0.0, when actually it uses the provided balance argument. To help students: Create comparison tables showing what each constructor does. Practice writing objects with different constructor calls. Emphasize that parameterized constructors provide flexibility in initialization. Watch for: assuming all constructors behave the same way, misunderstanding the purpose of constructor parameters.
Refer to the BankAccount class code below: which constructor will be invoked when creating a new BankAccount with no arguments?
public class BankAccount {
private String accountNumber;
private double balance;
// Public default constructor: sets default account number and zero balance.
public BankAccount() {
this("000000", 0.0); // Calls the parameterized constructor
}
// Public parameterized constructor: sets both fields.
public BankAccount(String accountNumber, double balance) {
this.accountNumber = accountNumber;
this.balance = balance;
}
// Private constructor: disallows constructing with only a number.
private BankAccount(String accountNumber) {
this(accountNumber, 0.0);
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on identifying which constructor handles specific object creation patterns (AP CSA standard). When creating objects in Java, the constructor invoked depends on the arguments provided - no arguments invokes the default constructor, while arguments must match a constructor's parameter list. Constructor visibility (public/private) also determines which can be called from outside the class. In the BankAccount class, new BankAccount() with no arguments matches and invokes the public BankAccount() default constructor. This constructor then chains to the two-parameter constructor, but the entry point is the no-argument constructor. Choice A is correct because the public BankAccount() constructor is specifically designed to handle no-argument object creation. Choice B is incorrect because the private constructor cannot be directly invoked from outside the class. To help students: Match constructor calls to constructor signatures. Emphasize the importance of parameter matching. Practice identifying which constructor runs for different new statements. Watch for: forgetting about access modifiers, confusion about which constructor is the entry point versus which does initialization.
In the Car code below, what is the purpose of the constructor in the given class?
public class Car {
private String make;
private String model;
private int year;
// Public default constructor: supplies default values
public Car() {
this("Unknown", "Unknown", 2026); // Chain to parameterized constructor
}
// Public parameterized constructor: initializes all instance variables
public Car(String make, String model, int year) {
this.make = make;
this.model = model;
this.year = year;
}
// Private constructor: internal helper
private Car(int year) {
this("Unknown", "Unknown", year);
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on the fundamental purpose of constructors in object-oriented programming. Constructors are special methods that execute when an object is instantiated, and their primary responsibility is to initialize the object's instance variables to ensure the object begins in a valid, usable state. In the provided Car code, all constructors ultimately initialize the make, model, and year fields - either with provided values or defaults. Choice A is correct because it identifies the essential purpose of constructors: initializing instance variables during object creation. Choice B is incorrect because constructors don't return values - they initialize the object being created, while methods that return values would be separate from constructors. To help students: Reinforce that constructors have no return type and run automatically during object creation, distinguishing them from regular methods. Watch for: students confusing constructors with getter methods or thinking constructors can return values.
In the BankAccount code below, what is the purpose of the constructor in the given class?
public class BankAccount {
private String accountNumber;
private double balance;
// Public default constructor: creates a basic account with defaults
public BankAccount() {
this("000000", 0.0); // Chain to parameterized constructor
}
// Public parameterized constructor: initializes accountNumber and balance
public BankAccount(String accountNumber, double balance) {
this.accountNumber = accountNumber;
this.balance = balance;
}
// Private constructor: internal helper for creating a zero-balance account
private BankAccount(String accountNumber) {
this(accountNumber, 0.0);
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on the fundamental purpose of constructors. Constructors are special methods that run when an object is created, and their primary purpose is to initialize the object's instance variables to ensure the object starts in a valid state. In the provided BankAccount code, both constructors ultimately initialize the accountNumber and balance fields - the default constructor does this by chaining to the parameterized constructor with default values. Choice A is correct because it identifies the core purpose of constructors: initializing fields when objects are created. Choice B is incorrect because constructors only initialize objects - they don't perform ongoing operations like computing interest, which would be done by regular methods. To help students: Emphasize that constructors run once at object creation and distinguish them from regular methods that perform operations. Watch for: students confusing constructor responsibilities with method responsibilities or thinking constructors can be called multiple times.
In the BankAccount code below, how does the parameterized constructor differ from the default constructor?
public class BankAccount {
private String accountNumber;
private double balance;
// Public default constructor: uses standard defaults
public BankAccount() {
this("000000", 0.0);
}
// Public parameterized constructor: uses provided values
public BankAccount(String accountNumber, double balance) {
this.accountNumber = accountNumber;
this.balance = balance;
}
// Private constructor: internal helper
private BankAccount(String accountNumber) {
this(accountNumber, 0.0);
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on the behavioral differences between default and parameterized constructors. The key difference is that parameterized constructors accept arguments and use those values for initialization, while default constructors provide predetermined values. In the provided BankAccount code, the parameterized constructor takes accountNumber and balance as parameters and assigns them directly to the instance fields, while the default constructor provides fixed values ("000000" and 0.0) when chaining. Choice B is correct because it accurately identifies that the parameterized constructor sets fields using the values passed as arguments. Choice A is incorrect because the default constructor takes no arguments - it's defined as BankAccount() with empty parentheses. To help students: Create side-by-side comparisons of constructor signatures and their behaviors, emphasizing parameter lists and value sources. Watch for: confusion about constructor signatures and which values come from parameters versus being hardcoded.
In the Book code below, how does the parameterized constructor differ from the default constructor?
public class Book {
private String title;
private String author;
// Public default constructor: sets a default title
public Book() {
this("Untitled", "Unknown"); // Chain to parameterized constructor
}
// Public parameterized constructor: sets both title and author
public Book(String title, String author) {
this.title = title;
this.author = author;
}
// Private constructor: internal helper for author-only books
private Book(String author) {
this("Untitled", author); // Chain to parameterized constructor
}
}
Explanation: This question tests understanding of Java constructors in AP Computer Science A, focusing on the differences between default and parameterized constructors. A default constructor takes no arguments and typically provides default values, while a parameterized constructor accepts arguments to initialize fields with specific values. In the provided Book code, the default constructor chains to the parameterized constructor with default values ("Untitled", "Unknown"), while the parameterized constructor directly assigns the provided title and author arguments to the instance fields. Choice B is correct because it accurately describes how the parameterized constructor initializes fields from its parameters. Choice A is incorrect because the default constructor doesn't take any arguments - it provides its own default values when chaining. To help students: Create comparison tables showing what each constructor does and practice identifying constructor purposes from code. Watch for: confusion about which constructor provides values versus which accepts them as parameters.