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.
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.
Which term refers to an instance of a class in Java?
Array
Variable
Object
Method
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.
Why might you choose inheritance over composition when designing an object-oriented system involving various types of user accounts?
When every account type needs completely unique data fields unrelated to other accounts.
Where no hierarchical relationship between account types exists or is necessary for the application logic.
If all account types share numerous common features and require only slight variations in functionalities.
If account types should operate independently without any shared base behavior or properties.
What is the value of x
after executing the following code snippet: int x = 10; if (x < 20) { x += 5; }
?
10
15
25
20
For implementing undo functionality in a text editor, which data structure provides the most suitable method for restoring previous states?
HashMap
ArrayList
Stack
Queue

How are we doing?
Give us your feedback and let us know how we can improve
In a recursive algorithm that models fractal patterns, what modification would significantly reduce stack overflow issues when generating high-detail depth levels?
Using a standard recursion pattern with system stack calls.
Increasing the JVM stack size manually before execution.
Limiting the recursion depth by using iterative loops instead.
Implementing tail recursion wherever possible.
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.