DOWNLOAD PDF.
*Core Domains*
*- Primitive Types*
*- Using Objects*
*- Boolean Expressions and if Statements*
*- Iteration*
*- Writing Classes*
*- Array*
*- ArrayList*
*- 2D Array*
*- Inheritance*
*- Recursion*
*- Ethical and Social Implications of Computing*
*Introduction*
*The AP Computer Science A assessment is designed to evaluate a candidate's proficiency in core Java programming concepts, object-orien
Section One: Questions 1–100
Question 1
Consider the following code segment:
int x = 5;
int y = 2;
double z = x / y;
What is the value of z after the code segment is executed?
A. 2.5
B. 2.0
C. 3.0
D. 0.0
,🟢 B. 2.0
🔴 RATIONALE: In Java, when two integers are divided using the / operator, integer division is performed, which truncates the fractional part.
Therefore, evaluates to 2. This integer result is then implicitly cast to a double when assigned to z, resulting in 2.0.
Question 2
A software company discovers that a legacy module contains a method that can cause an infinite loop if negative parameters are passed.
Modifying the legacy source code directly is prohibited due to strict regression compliance frameworks. Which design strategy represents the
most professional and ethically sound approach to resolve this issue?
A. Document the limitation in the developer user manual and allow the application to crash if negative inputs occur.
B. Implement a wrapper class or a subclass that overrides the method to perform input validation before invoking the legacy code.
C. Use a runtime configuration script to force close the application whenever a negative value is detected anywhere in memory.
D. Ignore the issue because legacy systems are exempt from current software compliance and safety standards.
🟢 B. Implement a wrapper class or a subclass that overrides the method to perform input validation before invoking the legacy code.
🔴 RATIONALE: Software engineering ethics and compliance frameworks require developers to mitigate known safety hazards and
operational risks. Implementing a wrapper class or subclass to intercept and validate input ensures system reliability and safety without
violating structural regression constraints.
Question 3
Consider the following method:
public static int compute(int n) {
if (n <= 1) {
return 1;
} else {
return n + compute(n - 1);
}
}
What value is returned as a result of the call compute(4)?
A. 10
B. 7
C. 24
D. 4
🟢 A. 10
🔴 RATIONALE: This is a recursive method that calculates the sum of integers from 1 to n. The execution path for compute(4) expands to 4
+ compute(3), which becomes 4 + (3 + compute(2)), then 4 + 3 + (2 + compute(1)). Since compute(1) returns 1, the total sum is 4 + 3 + 2 + 1
= 10.
Question 4
Consider the following code segment:
int[] elements = {3, 7, 2, 8, 5};
,int value = elements[1];
for (int i = 2; i < elements.length; i++) {
if (elements[i] > value) {
value = elements[i];
}
}
What is the value of the variable value after this loop executes?
A. 7
B. 2
C. 8
D. 5
🟢 C. 8
🔴 RATIONALE: The variable value is initialized to elements[1], which is 7. The loop iterates from index 2 to the end of the array, comparing
each element to value. It encounters 2 (not greater), 8 (greater, so value becomes 8), and 5 (not greater). The final value is 8.
Question 5
A developer needs to store an ordered list of transactional records where elements are frequently inserted and deleted from the middle of the
collection during runtime. Which data structure from the AP Java subset is most appropriate for optimizing these specific insertions and
deletions?
A. A primitive array
B. An ArrayList
C. A 2D array
D. A static array of objects
🟢 B. An ArrayList
🔴 RATIONALE: An ArrayList dynamically resizes and provides built-in methods (add and remove) to insert and delete elements at any
position. While primitive and static arrays have fixed dimensions that cannot grow or shrink dynamically, ArrayList handles variable-length
transactional data lists.
Question 6
Consider the following class declarations:
public class Vehicle {
public void start() {
System.out.print("V-Start ");
}
}
public class Car extends Vehicle {
public void start() {
super.start();
, System.out.print("C-Start ");
}
}
What is printed when the following code segment is executed?
Vehicle myCar = new Car();
myCar.start();
A. V-Start
B. C-Start
C. V-Start C-Start
D. C-Start V-Start
🟢 C. V-Start C-Start
🔴 RATIONALE: Due to polymorphism, the runtime environment executes the overridden start method in the Car class. Inside Car's start
method, super.start() is called first, which executes Vehicle's start method and prints "V-Start ". Then, the remaining statement in Car's
method prints "C-Start ".
Question 7
Under copyright and intellectual property standards, which of the following actions constitutes a direct violation of professional computing
ethics?
A. Using an open-source library in a commercial application while strictly adhering to its MIT license terms.
B. Modifying a publicly available algorithm to improve its execution time for internal research.
C. Copying a proprietary software library's compiled bytecode and distributing it as part of a commercial product without a license.
D. Writing an original class that implements an interface published in a public documentation standard.
🟢 C. Copying a proprietary software library's compiled bytecode and distributing it as part of a commercial product without a license.
🔴 RATIONALE: Distributing proprietary bytecode without an appropriate commercial license is a clear violation of intellectual property laws
and professional computing ethics. Adhering to open-source licenses, academic modification, and implementing public interfaces are legally
and ethically compliant acts.
Question 8
Consider the following boolean expression where a and b are initialized boolean variables:
!(!a && b)
Which of the following expressions is logically equivalent to the given expression?
A. a || !b
B. a && !b
C. !a || b
D. !a && !b
🟢 A. a || !b
🔴 RATIONALE: Applying De Morgan's Laws to the expression !(!a && b) distributes the negation inside the parentheses. The negation of !a
becomes a, the logical AND (&&) becomes a logical OR (||), and the negation of b becomes !b. This evaluates to a || !b.