Using Objects in AP Computer Science A
What advantage does using composition offer over inheritance in terms of software maintenance when adding new features to existing classes?
Composition leads to tighter inter-class relationships enhancing both reusability and reliability during updates.
Inheritance provides stronger coupling between superclasses and subclasses, simplifying feature addition processes significantly.
Composition allows new functionality through additional objects without altering existing hierarchy or risking impact on inherited behavior.
Utilizing inheritance enforces consistent implementation details throughout all derived classes making feature integration seamless.
What type of control structure would be most appropriate when you need to execute a block of code multiple times based on user input each time?
while loop
do-while loop
if-else chain
for loop
When declaring an array of integers in Java, what is the consequence of setting its length too large?
Automatic resizing when more space is needed.
Runtime errors when adding new elements.
Wasted memory space due to unused indices.
Improved performance due to pre-allocation.
In an e-commerce application's inventory system, what class structure promotes high cohesion within objects while allowing code reusability across different product categories?
Individual unrelated concrete classes for each product category containing duplicate basic attributes such as price and description.
One generic product class providing all possible properties across categories using boolean flags to activate relevant traits per instance.
Abstract classes defining core properties with subclass extensions for unique category traits like electronics having additional warranty details.
Multiple interfaces representing various product traits used in conjunction by each category-specific subclass to implement required behaviors.
What happens when an exception is thrown inside a method and it is not caught within that method?
The program immediately halts without any chance for recovery.
The exception gets logged automatically by Java's built-in logger.
The method terminates and the exception propagates up to the caller.
The compiler generates additional code to wrap the exception silently.
Which term refers to an instance of a class in Java?
Array
Variable
Object
Method
Without modifying existing codebase significantly, how could an existing single-threaded quicksort implementation be adapted for parallel processing?
Utilize Java's Fork/Join Framework entirely replacing quicksort logic.
Divide array into segments parallelly quicksort each then merge them sequentially.
Apply synchronized blocks liberally throughout current quicksort code.
Introduce wait()/notify() mechanisms around pivot selection logic.

How are we doing?
Give us your feedback and let us know how we can improve
If a method in a Java class is designed to find the maximum integer in an array and is mistakenly returning the first element instead, which could be the most likely cause?
The array is sorted in ascending order before finding the maximum.
The return statement is outside of the loop that iterates through the array elements.
An ArrayIndexOutOfBoundsException is thrown during execution.
The loop initializes the max variable with the first element but never updates it.
What is the value of x
after executing the following code snippet: int x = 10; if (x < 20) { x += 5; }
?
10
15
25
20
What does the 'this' keyword refer to within an instance method of a class?
The current object whose method or constructor is being invoked.
A superclass from which the current class inherits methods or fields.
The class that contains the method where 'this' keyword appears.
A static variable shared among all instances of a class.