wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

AP CSA Unit 3

Total questions: 27

Worksheet time: 31mins

Name
Class
Date
1.

A single value or object stored in a data structure, such as a one-dimensional array, is called a(n):

a)

Index

b)

Precondition

c)

Element

d)

Data Set

2.

Which Java keyword is used to declare and initialize a one-dimensional (1D) array, giving it a fixed size in memory?

a)

public

b)

final

c)

new

d)

void

3.

What is the primary definition of polymorphism in object-oriented programming?

a)

An error that occurs when a loop repeats too many times.

b)

A condition that must be true before a code segment executes.

c)

Where the same object or method has more than one form.

d)

The process of assigning a value to a specific index.

4.

Which expression is used to determine the number of elements a 1D array named data can store?

a)

data.length()

b)

data.length

c)

data.size()

d)

data[lastIndex]

5.

An enhanced for loop is typically preferred over a traditional for loop when your goal is to:

a)

Modify elements in the array.

b)

Traverse the entire array from first to last without modifying its elements.

c)

Start traversing the array at a specific index (e.g., index 3).

d)

Traverse the array backwards.

6.

What is the correct syntax for declaring and initializing an array of String objects called desserts using an initializer list containing "Cake" and "Pie"?

a)

String[] desserts = {"Cake", "Pie"};

b)

String desserts[] = new String;

c)

String desserts = {"Cake", "Pie"};

d)

String[] desserts = new String("Cake", "Pie");

7.

In a method designed to find the maximum value in a 1D array, when should the final calculated maximum be returned?

a)

Immediately after the first element is checked.

b)

Inside the loop, every time a new, larger value is found.

c)

After the loop has completed traversing the entire array.

d)

Inside the loop, only if the current element is smaller than the maximum found so far.

8.

A precondition for a method is best described as:

a)

The result or condition that must be true after the code finishes executing.

b)

The type of data that the method will return.

c)

A condition that must always be true just before the code segment is executed.

d)

The process of accessing elements one by one.

9.

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?

a)

Only Employee objects.

b)

Only Manager objects.

c)

Both Employee and Manager objects.

d)

Neither object type, as arrays must store only primitive types.

10.

Which of the following best describes the purpose of using an initializer list when declaring an array in Java?

a)

It allows you to declare an array without specifying its type.

b)

It provides a way to initialize an array with specific values at the time of declaration.

c)

It automatically sorts the array elements.

d)

It prevents the array from being modified.

11.

A single value or object stored in a data structure, such as a one-dimensional array, is called a(n) ______.

a)

Index

b)

Precondition

c)

Element

d)

Data Set

12.

Which term refers to a data structure that holds multiple values of the same data type?

a)

Data Set

b)

Data Structure

c)

One-dimensional (1D) array

d)

Nested Loop

13.

What is the integer value that indicates the position of a value (element) in a data structure?

a)

Length Attribute

b)

Index

c)

Loop Control Variable

d)

Value

14.

A comma-separated list of values or objects given inside curly braces ({ }) used to declare and initialize an array is known as a(n) ______.

a)

Postcondition

b)

Initializer list

c)

Text file

d)

Data abstraction

15.

Which term describes a condition that must always be true just before the execution of a code segment?

a)

Postcondition

b)

Precondition

c)

Algorithmic bias

d)

Loop control variable

16.

What is the definition of polymorphism?

a)

An error when a loop repeats too many times.

b)

A condition that must be true after code execution.

c)

A structure for organizing and storing data.

d)

Where the same object or method has more than one form.

17.

Which term refers to an error that occurs when a loop repeats one time too many or one time too few?

a)

Nested loop

b)

Syntax error

c)

Array index out of bounds exception

d)

Off-by-one error

18.

To increase a value by one using an operator is called:

a)

Decrement

b)

Postcondition

c)

Increment

d)

Traverse

19.

A loop that is placed structurally inside of another loop is known as a(n) ______.

a)

Infinite loop

b)

Nested loop

c)

Syntax loop

d)

Condition loop

20.

Which of the following best describes the concept of polymorphism in programming?

a)

A method that can only be used once in a program.

b)

An object or method that can exist in multiple forms.

c)

A variable that changes its type during execution.

d)

A loop that repeats indefinitely.

21.

String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


What is the correct way to find the length of "txt" string?

a)

int len = length(txt);

b)

float len = txt.length();

c)

int len = txt.length();

d)

double len = length(txt);

22.

String x = "10";

String y = "20";

String z = x + y;

System.out.println(z);

Guess the output.

a)

1020

b)

10 20

c)

30

d)

"10 20"

23.

int[] myArray = {11, 22, 33, 44, 55};

which code is correct to print length of above int-array?

a)

System.out.println(int[].myArray.length());

b)

System.out.println(myArray.length);

c)

System.out.println(myArray.length());

d)

System.out.println(int[].myArray.size());

24.

int [ ] nums = {2, 3, 5, 8, 9, 11};

How would you access the fourth element in nums

a)

nums[4]

b)

nums[3]

c)

nums(4)

d)

nums(3)

25.

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]);

}

}

}

a)

10 20 30 40 50

b)

Compiler Error

c)

10 20 30 40

26.
What does the following segment of code print out? int[] numArray = { 2, 7, 4, 12, 0, 2 };
System.out.println("Number: " + numArray[0]);
a)
Number: 2
b)
Number: 7
c)
Number: 4
d)
Number: 12
27.

class Test {

public static void main(String args[]) {

int arr[2];

System.out.println(arr[0]);

System.out.println(arr[1]);

}

}

a)

0

0

b)

garbage value

garbage value

c)

Compiler Error

d)

Exception