NEW
Font size
WorksheetsAP CSA Unit 3
Total questions: 27
Worksheet time: 31mins
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 Java keyword is used to declare and initialize a one-dimensional (1D) array, giving it a fixed size in memory?
public
final
new
void
What is the primary definition of polymorphism in object-oriented programming?
An error that occurs when a loop repeats too many times.
A condition that must be true before a code segment executes.
Where the same object or method has more than one form.
The process of assigning a value to a specific index.
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]
An enhanced for loop is typically preferred over a traditional for loop when your goal is to:
Modify elements in the array.
Traverse the entire array from first to last without modifying its elements.
Start traversing the array at a specific index (e.g., index 3).
Traverse the array backwards.
What is the correct syntax for declaring and initializing an array of String objects called desserts using an initializer list containing "Cake" and "Pie"?
String[] desserts = {"Cake", "Pie"};
String desserts[] = new String;
String desserts = {"Cake", "Pie"};
String[] desserts = new String("Cake", "Pie");
In a method designed to find the maximum value in a 1D array, when should the final calculated maximum be returned?
Immediately after the first element is checked.
Inside the loop, every time a new, larger value is found.
After the loop has completed traversing the entire array.
Inside the loop, only if the current element is smaller than the maximum found so far.
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.
You have an array declared as Employee[] staffList;. If Manager is a subclass of Employee, which of the following objects can be successfully stored in staffList due to polymorphism?
Only Employee objects.
Only Manager objects.
Both Employee and Manager objects.
Neither object type, as arrays must store only primitive types.
Which of the following best describes the purpose of using an initializer list when declaring an array in Java?
It allows you to declare an array without specifying its type.
It provides a way to initialize an array with specific values at the time of declaration.
It automatically sorts the array elements.
It prevents the array from being modified.
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 term refers to a data structure that holds multiple values of the same data type?
Data Set
Data Structure
One-dimensional (1D) array
Nested Loop
What is the integer value that indicates the position of a value (element) in a data structure?
Length Attribute
Index
Loop Control Variable
Value
A comma-separated list of values or objects given inside curly braces ({ }) used to declare and initialize an array is known as a(n) ______.
Postcondition
Initializer list
Text file
Data abstraction
Which term describes a condition that must always be true just before the execution of a code segment?
Postcondition
Precondition
Algorithmic bias
Loop control variable
What is the definition of polymorphism?
An error when a loop repeats too many times.
A condition that must be true after code execution.
A structure for organizing and storing data.
Where the same object or method has more than one form.
Which term refers to an error that occurs when a loop repeats one time too many or one time too few?
Nested loop
Syntax error
Array index out of bounds exception
Off-by-one error
To increase a value by one using an operator is called:
Decrement
Postcondition
Increment
Traverse
A loop that is placed structurally inside of another loop is known as a(n) ______.
Infinite loop
Nested loop
Syntax loop
Condition loop
Which of the following best describes the concept of polymorphism in programming?
A method that can only be used once in a program.
An object or method that can exist in multiple forms.
A variable that changes its type during execution.
A loop that repeats indefinitely.
String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
What is the correct way to find the length of "txt" string?
int len = length(txt);
float len = txt.length();
int len = txt.length();
double len = length(txt);
String x = "10";
String y = "20";
String z = x + y;
System.out.println(z);
Guess the output.
1020
10 20
30
"10 20"
int[] myArray = {11, 22, 33, 44, 55};
which code is correct to print length of above int-array?
System.out.println(int[].myArray.length());
System.out.println(myArray.length);
System.out.println(myArray.length());
System.out.println(int[].myArray.size());
int [ ] nums = {2, 3, 5, 8, 9, 11};
How would you access the fourth element in nums
nums[4]
nums[3]
nums(4)
nums(3)
Predict the output?
public class Main {
public static void main(String args[]) {
int arr[] = {10, 20, 30, 40, 50};
for(int i=0; i < arr.length; i++)
{
System.out.print(" " + arr[i]);
}
}
}
10 20 30 40 50
Compiler Error
10 20 30 40
System.out.println("Number: " + numArray[0]);
class Test {
public static void main(String args[]) {
int arr[2];
System.out.println(arr[0]);
System.out.println(arr[1]);
}
}
0
0
garbage value
garbage value
Compiler Error
Exception
