Writing Classes in AP Computer Science A
If a class contains a public void method named 'updateScore', what can be inferred about this method?
It returns an integer value representing a score.
It can be accessed from outside the class and does not return any value.
It cannot change the state of an object because it's void.
It is private and cannot be accessed directly from outside the class.
Which method signature correctly indicates overloading when added to a class containing public void processData(int data)?
public void processData(int number)
public int processData(double dataValue)
private void processData(int numData)
public static void processData(int info)
What happens when a primitive value is passed as a parameter to a method in Java?
One cannot pass a primitive value to a method.
The method receives a copy of the value.
The primitive value is turned into an object.
The method receives a copy of the reference to the value.
If you need a method that checks whether its input integer parameter is prime or not, what should be its return type?
double
boolean
void
int
What is the purpose of parameters?
To specify the access level of the method
To define the body of the method
To determine the name of the method
To allow values to be passed into the method
Which of the following is NOT an access modifier in Java?
private
global
protected
public
If a class has a private instance variable named 'radius', which method signature would be appropriate for setting its value?
public void setRadius(double newRadius)
void updateRadius(double newRadius)
public double getRadius()
private double setRadius(double newRadius)

How are we doing?
Give us your feedback and let us know how we can improve
What alteration can be made so a method designed to find and return only prime numbers from an integer list inadvertently returns all odd numbers instead?
Removing or modifying the check for divisibility by even numbers other than two.
Initialising count variables outside of loops used for counting factors.
Adding break statements inside nested loops used for checking factors.
Increasing efficiency by only checking up to square root of each number.
What is the result of calling Arrays.binarySearch(arr, 4)
if arr
is an array containing {1, 3, 4, 6, 8}
after being sorted?
The value 4
.
An IndexOutOfBoundsException error.
The index of value 4
, which is 2
.
A negative number indicating that the element was not found.
Given two different algorithms with time complexities of and , which scenario would most likely show a noticeable performance difference between them?
When processing a large dataset
When each algorithm processes one item at a time
When processing a small dataset
When both algorithms are implemented using recursion