AP Computer Science A Practice Quiz: Constructors
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 10 questions to check your progress.
Question 1 of 10
All Questions (10)
A) To return a value after performing a calculation.
B) To set the initial state of an object by initializing its instance variables.
C) To define the behavior and methods an object can perform.
D) To store a reference to the newly created object.
Correct Answer: B
Based on the provided content, "A constructor is used to set the initial state of an object, which should include initial values for all instance variables."
A) null
B) 1
C) 0
D) It will cause a compilation error.
Correct Answer: C
The provided content states, "The default value for an attribute of type int is 0."
A) "" (an empty string)
B) "name"
C) 0
D) null
Correct Answer: D
`String` is a reference type. The constructor only initializes `studentID`. Since `name` is not initialized, it receives its default value. According to the content, "The default value of a reference type is null."
A) Car myCar = new Car();
B) Car myCar = new Car("Sedan", 2023);
C) Car myCar = new Car; myCar.model = "Sedan"; myCar.year = 2023;
D) Car("Sedan", 2023);
Correct Answer: B
The content states, "Constructor parameters, if specified, provide data to initialize instance variables." The constructor for `Car` requires a `String` and an `int` as parameters. Option B correctly provides these arguments during object creation to initialize the instance variables.
A) The `players` array is `{"Alice", "Bob", "Charlie"}`.
B) The `players` array is `{"Zoe", "Bob", "Charlie"}`.
C) The `players` instance variable is `null`.
D) The code results in a runtime error.
Correct Answer: B
The constructor assigns the instance variable `players` to the same memory reference as the `initialPlayers` parameter. Because a copy was not made, the instance variable holds a reference to the original `starters` object. When the original `starters` array is modified, the change is reflected in the `varsity` object's `players` variable.
A) The constructor should assign the parameter's reference directly to the instance variable.
B) The constructor should declare the instance variable as `final`.
C) The constructor should initialize the instance variable with a copy of the object passed as a parameter.
D) The constructor should refuse to accept mutable objects as parameters.
Correct Answer: C
The content explicitly states, "When a mutable object is a constructor parameter, the instance variable should be initialized with a copy of the referenced object. In this way, the instance variable does not hold a reference to the original object."
A) `pageCount` is 0, `isHardcover` is false.
B) `pageCount` is 0, `isHardcover` is true.
C) Both are `null`.
D) The code will not compile because not all instance variables are initialized.
Correct Answer: A
The constructor only initializes the `title`. The other instance variables, `pageCount` and `isHardcover`, are not explicitly initialized, so they receive their default values. The content states the default for `int` is 0 and the default for `boolean` is `false`.
A) To serve as temporary variables only within the constructor.
B) To define the attributes that will be initialized in the constructor to represent an object's state.
C) To store the return values of the class's methods.
D) To count the number of objects created from the class.
Correct Answer: B
The content states to "declare instance variables for the attributes to be initialized in the body of the constructors of a class." This indicates that instance variables represent the attributes that define an object's state.
A) 0
B) 0.0
C) null
D) 1.0
Correct Answer: B
According to the provided content, "The default value of an attribute of type double is 0.0."
A) It runs all the methods in the class once.
B) It assigns memory for the object on the heap.
C) It provides initial values for all the instance variables, defining the object's starting properties.
D) It connects the object to other objects in the program.
Correct Answer: C
The content states, "A constructor is used to set the initial state of an object, which should include initial values for all instance variables." This directly corresponds to defining the object's starting properties by giving values to its attributes.