PrepGo

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

Which operator is used to call an instance method on an object in Java?

All Questions (9)

Which operator is used to call an instance method on an object in Java?

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.'

Consider the class `public class Student { public void study() { /* ... */ } }`. If `s1` is an object of the `Student` class, which of the following shows the correct syntax to call the `study` method?

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()`).

What is the result of attempting to execute the following code snippet? ```java public class Computer { public void boot() { System.out.println("Booting up..."); } } Computer myPC = null; myPC.boot(); ```

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.

Consider the following code: ```java public class ScoreKeeper { public int getScore() { return 100; } } ScoreKeeper game = new ScoreKeeper(); int finalScore = game.getScore(); ``` What is the value of the `finalScore` variable after this code is executed?

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.

Which of the following is a key characteristic of calling an instance method?

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.

What is the primary consequence of calling a method on a reference variable that has not been initialized and holds a `null` value?

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.

Analyze the following code segment. What is the final result? ```java public class LightSwitch { public void flip() { /* ... */ } } LightSwitch kitchenSwitch = new LightSwitch(); kitchenSwitch = null; kitchenSwitch.flip(); ```

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`.

To call an instance method named `calculate()` on an object named `myObject`, which of the following is the correct procedure?

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.

Under which condition will a call to an instance method, such as `car.drive()`, definitely result in a `NullPointerException`?

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.