NEW
Font size
WorksheetsAP CSA Midterm 2026
Total questions: 15
Worksheet time: 8mins
A programmer uses an AI Large Language Model (LLM) to generate a method for a loan application program. The initial prompt is "Write a method to approve or deny loan applications based on historical data." After testing, it's found the generated code disproportionately denies applicants from a specific zip code. According to the concepts discussed in the lesson, what does this situation most likely represent?
A syntax error introduced by the LLM that caused the program to malfunction for specific inputs.
A simple 'glitch' or logic error in the AI's algorithm that can be fixed by rerunning the same prompt.
An effective use of AI to decrease development time, with the outcome being an unavoidable consequence of data-driven programming.
A systemic issue where the AI reflects biases present in its training data, requiring deliberate human intervention and a more articulated program design.
Using the analogy where a `class` is a blueprint for a house, which statement most accurately describes the process of building a specific house located at '123 Main St' in Java?
Instantiating an `object` from the `House` class by calling the `House` constructor, and assigning it to a reference variable analogous to the address '123 Main St'.
Calling the `instantiate()` method on the `House` class, with the `constructor` and '123 Main St' as arguments.
Defining a new `class` called `HouseAt123MainSt` that contains the attributes from the original `House` blueprint.
Creating a `constructor` named `houseAt123MainSt` within the `House` blueprint to define the object's specific state.
A `Painter` object is programmed to navigate a maze and paint the exit square blue. The program compiles and runs without crashing, but the `Painter` perfectly navigates the maze and instead paints the square next to the exit. What type of error does this scenario exemplify?
A syntax error.
A logic error.
An exception.
A run-time error.
A programmer uses the `myPainter.move()` method without needing to know the specific lines of code that update the painter's coordinates. Later, the same programmer crafts a detailed prompt for an AI to generate code for drawing a flag, specifying stripe dimensions and colors. Which concepts are best illustrated by these two actions, respectively?
Object-oriented programming and debugging a logic error.
Instantiation and using a `while` loop.
Procedural abstraction and the necessity for specific, well-planned prompts for effective AI code generation.
Using a Large Language Model (LLM) and procedural abstraction.
Review the following code snippet, intended to have a `Painter` object named `pablo` turn left and then move forward. Which line contains a conceptual error regarding object-oriented principles? java 1. public class MyNeighborhood { 2. public static void main(String[] args) { 3. Painter pablo = new Painter(); 4. Painter.turnLeft(); 5. pablo.move(); 6. } 7. }
Line 2; the `main` method is a static context and cannot be used to create non-static objects like `Painter`.
Line 4; methods representing behaviors must be called on a specific object instance (`pablo`), not on the class blueprint (`Painter`).
Line 3; a reference variable like `pablo` must be declared with the `new` keyword on a separate line.
Line 5; the `move()` method requires a parameter specifying direction, such as `move("forward")`.
Consider the `Gadget` class below.
Which of the following code segments, when placed in a method in another class, will create a `Gadget` object with a `version` of 1 and a `model` of "Standard"?
Gadget myGadget = new Gadget.this(1, "Standard");
Gadget myGadget = new Gadget();
Gadget myGadget = new Gadget(0, null);
Gadget myGadget = new Gadget(1, "Standard");
Examine the `GamePlayer` class.
What are the values of the instance variables `score` and `level` after the following code is executed?
GamePlayer player1 = new GamePlayer();
player1.setLevel(5);
player1.setLevel(3);
`score` is 0, `level` is 8
`score` is 0, `level` is 5
`score` is 0, `level` is 1
`score` is 0, `level` is 3
Consider the following class definitions.
What is printed when the following code segment is executed?
java
Car myCar = new Car("Sedan");
System.out.println(myCar);
An error occurs because `Car` does not have a `toString` method.
A string containing the memory address of the `myCar` object.
Wheels: 4
Wheels: 0
What is the output of the following code snippet?
Value: 14 - 0
Value: 3.5 - 2
Value: 3 - 2
Value: 2 - 2
Which of the following is an example of encapsulation in Java?
Declaring instance variables as private and providing public getter and setter methods
Overloading methods with different parameters
Creating multiple constructors in a class
Using inheritance to extend a class
What is the fundamental difference between a class and an object in Java?
A. A class is an instance of an object, while an object is the template for creating classes
B. A class is a blueprint or template, while an object is an instance created from it
C. A class stores data only, while an object only performs actions
D. A class is created using the new keyword, while an object is declared with class
What is the role of a constructor?
To destroy an object when it is no longer needed
To create and initialize a new object
To store an object's attributes in memory
To call methods automatically whenever a class is used
A precondition for a method is best described as:
The result or condition that must be true after the code finishes executing.
The type of data that the method will return.
A condition that must always be true just before the code segment is executed.
The process of accessing elements one by one.
A single value or object stored in a data structure, such as a one-dimensional array, is called a(n):
Index
Precondition
Element
Data Set
Which expression is used to determine the number of elements a 1D array named data can store?
data.length()
data.length
data.size()
data[lastIndex]
