PrepGo

AP Computer Science A Practice Quiz: Calling Class 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 keyword is used in a method's header to identify it as a class method?

All Questions (9)

Which keyword is used in a method's header to identify it as a class method?

A) class

B) public

C) static

D) void

Correct Answer: C

According to the provided content, 'Class methods include the keyword static in the header before the method name.' The other keywords have different purposes.

What is the primary characteristic that distinguishes a class method from an instance method?

A) Class methods can only be called from within their own class.

B) Class methods are associated with the class itself, not with any specific instance of the class.

C) Class methods must always return a value.

D) Class methods cannot have any parameters.

Correct Answer: B

The content explicitly states, 'Class methods are associated with the class, not instances of the class.' This is their defining feature.

Consider a class named `Converter` that contains a public class method `inchesToCm()`. From a different class, what is the typical syntax for calling this method?

A) Converter.inchesToCm()

B) new Converter.inchesToCm()

C) inchesToCm(Converter)

D) A new instance of Converter must be created before calling the method.

Correct Answer: A

The provided text states, 'Class methods are typically called using the class name along with the dot operator.' Therefore, `Converter.inchesToCm()` is the correct syntax.

Consider the following code snippet from a class named `MyRobot`: ```java public class MyRobot { public static int getRobotCount() { // implementation not shown return 0; } public void moveForward() { // Call 1 int count1 = getRobotCount(); // Call 2 int count2 = MyRobot.getRobotCount(); } } ``` Based on the rules for calling class methods, which statement is true regarding the calls within the `moveForward` method?

A) Only Call 1 is valid.

B) Only Call 2 is valid.

C) Both Call 1 and Call 2 are valid ways to call the class method from within its defining class.

D) Neither call is valid because a class method cannot be called from an instance method.

Correct Answer: C

The content states, 'When the method call occurs in the defining class, the use of the class name is optional in the call.' Therefore, both calling with the class name (`MyRobot.getRobotCount()`) and without it (`getRobotCount()`) are valid.

Consider the following class definition: ```java public class TextUtils { public static String createHeader(String text) { return "== " + text + " =="; } } ``` What is the result of executing the following line of code? `System.out.println(TextUtils.createHeader("Welcome"));`

A) Welcome

B) == Welcome ==

C) TextUtils.Welcome

D) The code will produce a compilation error.

Correct Answer: B

The code calls the `static` class method `createHeader` on the `TextUtils` class, passing "Welcome" as the argument. The method concatenates this string with "== " and " ==", resulting in the output "== Welcome ==".

Examine the `Calculator` class below: ```java public class Calculator { private static int add(int x, int y) { return x + y; } public static int compute(int val) { int sum = add(val, 10); return sum * 2; } } ``` What is the result of the call `Calculator.compute(5)`?

A) 15

B) 20

C) 30

D) The code will not compile because `add` is a private method.

Correct Answer: C

The call `Calculator.compute(5)` executes the `compute` method. Inside `compute`, the class method `add` is called with arguments 5 and 10, which returns 15. This result (15) is then multiplied by 2, returning a final value of 30. The call to `add` is valid because it occurs within the defining class.

Given the following class: ```java public class Config { public static String getVersion() { return "1.0"; } } ``` And the following code in another class: `Config myConfig = new Config();` The `getVersion` method is associated with which of the following?

A) The instance `myConfig` only.

B) Any instance of the `Config` class.

C) The `Config` class itself.

D) The constructor of the `Config` class.

Correct Answer: C

Because `getVersion` is a `static` method, it is a class method. The provided content states that 'Class methods are associated with the class, not instances of the class.' Therefore, the method is associated with the `Config` class, not the `myConfig` instance.

Consider the following method definition within a class named `Validator`: `public boolean isLengthValid(String input, int min)` Which of the following statements is true?

A) This is a class method because it is public.

B) This is a class method and can be called using `Validator.isLengthValid(...)`.

C) This is not a class method because it is missing the `static` keyword.

D) This is not a class method because it returns a `boolean`.

Correct Answer: C

The content specifies that 'Class methods include the keyword static in the header'. Since this method header does not contain the `static` keyword, it is an instance method, not a class method. Therefore, it cannot be called using the class name.

What is the result of attempting to compile and run the following code? ```java // In a file named Message.java public class Message { public String format(String text) { return "<" + text + ">"; } } // In another class's main method public static void main(String[] args) { String result = Message.format("alert"); System.out.println(result); } ```

A) The code compiles and prints `<alert>`.

B) The code compiles but results in a runtime error.

C) The code fails to compile because `format` is not a class method.

D) The code fails to compile because `main` cannot call methods from other classes.

Correct Answer: C

The method `format` in the `Message` class is missing the `static` keyword, so it is an instance method, not a class method. The code attempts to call it using the class name (`Message.format`), which is the syntax for calling a class method. This mismatch will cause a compilation error.