AP Computer Science A Practice Quiz: Calling Instance Methods
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 9 questions to check your progress.
Question 1 of 9
All Questions (9)
A) . (dot)
B) -> (arrow)
C) :: (scope resolution)
D) () (parentheses)
Correct Answer: A
The provided content states: 'The dot operator is used along with the object name to call instance methods.'
A) Student.study();
B) s1.study();
C) study(s1);
D) new Student().study;
Correct Answer: B
Instance methods are called on objects of the class. The correct syntax is to use the object name (`s1`), followed by the dot operator, and then the method name with parentheses (`study()`).
A) The code fails to compile.
B) The text "Booting up..." is printed to the console.
C) The program runs but does nothing.
D) A `NullPointerException` is thrown at runtime.
Correct Answer: D
The object reference `myPC` is explicitly set to `null`. The content states that 'A method call on a null reference will result in a NullPointerException.' Therefore, calling `myPC.boot()` will cause this runtime error.
A) 0
B) 100
C) null
D) An error occurs.
Correct Answer: B
The code develops an object `game` and calls the instance method `getScore()` on it. This method returns the integer 100, which is then assigned to the `finalScore` variable. The result of the method call is 100.
A) It must be called using the class name.
B) It operates on a specific instance (object) of a class.
C) It will always result in a `NullPointerException`.
D) It does not require an object to be created first.
Correct Answer: B
The content specifies that 'Instance methods are called on objects of the class.' This means they are associated with and operate on a specific object, also known as an instance.
A) A compile-time error, because the compiler detects the null reference.
B) A runtime error known as a `NullPointerException`.
C) The method call is ignored, and the program continues.
D) A default object is created automatically to handle the method call.
Correct Answer: B
The provided content explicitly states: 'A method call on a null reference will result in a NullPointerException.' This is a runtime error, as the check for null happens when the code is executed, not when it is compiled.
A) The code compiles and runs without error.
B) The code fails to compile because `kitchenSwitch` is reassigned.
C) A `NullPointerException` is thrown when `kitchenSwitch.flip()` is called.
D) An `IllegalStateException` is thrown.
Correct Answer: C
An object of `LightSwitch` is created and assigned to `kitchenSwitch`. However, the next line reassigns `kitchenSwitch` to `null`. The subsequent method call, `kitchenSwitch.flip()`, is an attempt to call a method on a null reference, which results in a `NullPointerException`.
A) Use the object name and the dot operator: `myObject.calculate()`.
B) Use the class name and the dot operator: `ClassName.calculate()`.
C) Pass the object as an argument to the method: `calculate(myObject)`.
D) Create a new object inside the call: `new myObject.calculate()`.
Correct Answer: A
Based on the rule 'The dot operator is used along with the object name to call instance methods,' the correct syntax is `objectName.methodName()`. Therefore, `myObject.calculate()` is the correct call.
A) When the `drive` method has no return value (is void).
B) When the `Car` class has no constructor.
C) When the `car` object reference has a value of `null`.
D) When the `drive` method is called outside of the `Car` class.
Correct Answer: C
The content directly links the `NullPointerException` to a specific cause: 'A method call on a null reference will result in a NullPointerException.' Therefore, if the `car` reference is `null`, the call will fail with this error.