Writing Classes in AP Computer Science A
Which type of code is typically ignored by the compiler and does not affect the execution of the program?
Statements
Comments
Annotations
Directives
What is the primary reason for using Javadoc comments in a Java program?
To provide step-by-step instructions on how to compile and run the program.
To automatically generate standardized API documentation from source code.
To add detailed explanations inside methods for complex algorithms.
To indicate changes and updates made during different versions of the program.
Which type of comment may include preconditions and postconditions?
Block comments
Multi-line comments
Single-line comments
Javadoc comments
When documenting code that includes both iterative and recursive solutions to calculate Fibonacci numbers, what comment correctly justifies the use of recursion despite potential performance concerns?
Recursive solution used for educational purposes though iterative may be more efficient due to stack overflow risk with large inputs.
Recursion chosen as it enables parallel computation of Fibonacci numbers yielding faster runtime on multi-core processors.
Iterative version avoided because recursion offers better space complexity by reducing variable usage within loops.
Recursion provides a clearer and more concise code structure, which outweighs any efficiency gains from iteration.
In a program that sorts an array of integers using different algorithms, which comment best explains the reason for choosing QuickSort over other sorting methods given its average case behavior?
QuickSort is selected due to its inherent simplicity and ease of implementation in comparison to other sorting algorithms.
We use QuickSort as it guarantees time complexity in the worst-case scenario, unlike others.
QuickSort's ability to sort without additional memory makes it the preferred choice over MergeSort or HeapSort.
QuickSort is chosen for its average time complexity, making it efficient for large datasets.
What potential disadvantage could arise from choosing inheritance over composition in large-scale object-oriented programming projects?
The final classes are immutable, preventing further extension through additional subclassing or modification.
There could be increased complexity due to deep hierarchy trees which can make maintenance difficult.
Objects become less reusable because they are limited to single-inheritance structures in certain languages like Java.
Performance overhead increases dramatically as objects require more memory space due to inherited properties.
When designing classes for a new software system, why would developers use composition instead of inheritance?
Developers choose composition to achieve flexibility by combining object behaviors at runtime.
Using inheritance can lead to tightly coupled code which is harder to maintain than using composition.
Composition reduces the ability for different parts of a program to interact and communicate data.
They prefer composition as it simplifies the creation of subclasses with additional functionality.

How are we doing?
Give us your feedback and let us know how we can improve
What kind of information would typically NOT be included in documentation comments?
The parameters used by a method.
The return value type and its meaning.
A description of what a method does.
The author's personal opinion about unrelated topics.
When documenting code, which audience should you keep in mind while writing comments?
Customers who purchased software products.
People looking for entertainment while reading source codes.
Computers that compile your source codes.
Other developers who may read or maintain your code.
Where would you typically place a block comment in Java?
At the end of each line of code for clarification purposes only.
After main method declaration exclusively.
Typically before a block of code to explain its purpose or logic.
In random locations as long as it's somewhere within your class file.