Using Objects in AP Computer Science A
What is an object in Java?
An actual instance of an object.
A blueprint for a house.
A template that defines what an object is like and what the object can do.
A reference type that combines primitive and reference data types.
Considering encapsulation principles in OOP, which action should be avoided when dealing with classes and objects?
Allowing direct access modification of class fields from outside methods.
Using getter methods to retrieve field values.
Implementing setter methods that validate data before modifying fields.
Wrapping related variables and methods together into single units as classes.
If two algorithms have been analyzed and one has a complexity classed as while another has , which scenario would likely influence choosing the former over the latter?
Problems where maintaining sorted data elements is not essential
Small-scale applications where execution time differences are negligible
Problems involving large datasets where performance significantly degrades with quadratic complexity
Situations requiring precise control over low-level memory management
When sorting an array of integers with a large number of elements, which algorithm generally takes the least amount of time when the data is nearly sorted?
Merge sort
Insertion sort
Bubble sort
Selection sort
What Java keyword would you use to repeat a block of code until a specified condition becomes false?
do
while
break
for
Why is understanding recursion relevant when developing algorithms?
Recursion provides a way to solve complex problems by breaking them down into simpler subproblems.
Recursion simplifies debugging by reducing the number of lines in code.
Recursion eliminates the need for data storage in a program.
Recursion speeds up every type of algorithm regardless of context.
When analyzing an algorithm for efficiency, what metric is commonly used to describe its performance as input size grows?
Compilation time
Number of variables
Big O notation
Lines of code

How are we doing?
Give us your feedback and let us know how we can improve
What is a potential bug when using the following code snippet in a class method?
public void addToCart(Item item) { cart.add(new Item(item)); }
It creates unnecessary duplicates of items when adding them to the cart.
It uses polymorphism incorrectly by casting Item objects.
It violates encapsulation by directly accessing properties of Item.
There’s an infinite loop because adding items never terminates.
Which control structure could be used to execute a block of code multiple times based on a condition being true?
while loop
switch statement
if statement
method declaration
Which of the following is a valid reason for using breakpoints in debugging?
To pause the execution of a program and inspect variables.
To compile the code more quickly.
To speed up the execution of a loop.
To change the value returned by a method.