AP Computer Science A Practice Quiz: Methods: How to Write Them
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 store primitive data for an object.
B) To define the behaviors of an object.
C) To create new objects of the class.
D) To declare the class's instance variables.
Correct Answer: B
The content states that methods are developed to 'define behaviors of an object'. Storing data is the role of instance variables, and creating objects is typically done via a constructor.
A) public void checkStatus()
B) public boolean checkStatus()
C) public return boolean checkStatus()
D) public checkStatus() boolean
Correct Answer: B
A non-void method's header must include the return type (in this case, 'boolean') in place of the keyword 'void'. The return type precedes the method name.
A) To modify the value of an instance variable.
B) To allow other classes to obtain a copy of an instance variable's value.
C) To perform a calculation without returning a value.
D) To initialize an object's state when it is created.
Correct Answer: B
The content explicitly states, 'An accessor method allows objects of other classes to obtain a copy of the value of instance variables or class variables.' Methods that modify values are typically called mutator methods.
A) 10
B) 50
C) 60
D) The code will produce a compile-time error.
Correct Answer: A
When the primitive value 'myNum' is passed to the 'attemptChange' method, the parameter 'val' receives a copy of its value. The change to 'val' inside the method does not affect the original 'myNum' variable.
A) A void method
B) A constructor
C) An accessor method
D) A static method
Correct Answer: C
This is a non-void method that allows other objects to obtain the value of an instance variable (the balance). This fits the definition of an accessor method.
A) 5
B) 10
C) 0
D) The value is unpredictable.
Correct Answer: A
Because primitive types are passed by value, the 'swap' method receives copies of the values of x and y. The method successfully swaps its local copies, 'a' and 'b', but the original variables 'x' and 'y' in the calling scope remain unchanged.
A) The use of the `public` keyword.
B) The presence of parameters in parentheses.
C) The inclusion of a specific return type instead of the keyword `void`.
D) The method name must start with 'get'.
Correct Answer: C
The content states that a non-void method's header 'includes the return type in place of the keyword void'. This is the fundamental difference in their declarations.
A) 10
B) 20
C) 30
D) The code will not compile because the return value is not used.
Correct Answer: B
Even though the `addTen` method returns a new value (30), the calling code does not assign this returned value back to the `val` variable. Because `val` is a primitive, the original variable is unaffected by the operations inside the method. Therefore, `val` remains 20.
A) The parameter is a reference to the original argument's memory location.
B) The parameter is initialized with a copy of the argument's value.
C) The parameter must have a different data type than the argument.
D) Any change to the parameter will also change the argument.
Correct Answer: B
This directly tests the rule from the provided content: 'When an argument is a primitive value, the parameter is initialized with a copy of that value.' This is the principle of pass-by-value.
A) 80 40
B) 80 20
C) 60 40
D) 60 20
Correct Answer: A
The primitive `attackPower` (40) is passed to `takeDamage`. The parameter `damageAmount` gets a copy (40). Inside the method, `damageAmount` is changed to 20 (40 / 2). The player's health is then updated: `100 - 20 = 80`. After the method call, the original `attackPower` variable is unchanged because it's a primitive passed by value. The output is the new health (80) and the original `attackPower` (40).