AP CSA Final

0.0(0)
studied byStudied by 2 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/39

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

40 Terms

1
New cards

Assume that the BankAccount is a predefined class and that the declaration BankAccount[] firstEmpireBank; has already been performed. Then the following instruction reserves memory space for

1000 reference variables, each of which point to a single BankAccount entry

2
New cards

Which of the following is a legal way to declare and instantiate an array of 10 Strings?

String[] s = new String[10];

3
New cards

The “off-by-one” error associated with arrays arises because

the first array index is 0 and programmers may start at index 1, or may use a loop that goes one index too far

4
New cards

We compare sorting algorithms by examining

the number of instructions executed by the sorting algorithm

5
New cards

Both the Insertion Sort and the Selection Sort algorithms have efficiencies on the order of ____ where n is the number of values in the array being sorted

6
New cards

Consider the array declaration and instantiation: int[] arr = new int[5]; Which of the following is true about arr?

It stores 5 elements with legal indices between 0 and 4

7
New cards

If an int array is passed as a parameter to a method, which of the following would adequately define the parameter list for the method header?

(int[] a)

8
New cards

The following code accomplishes which of the tasks written below? Assume list is an int array that stores positive int values only.

foo = 0;

for (j=0; j<list.length; j++)
if (list[j] > foo) foo = list[j];

it stores the largest value in list (the maximum) in foo

9
New cards

Assume an int array, candy, stores the number of candy bars sold by a group of children where candy[j] is the number of candy bars sold by child j. Assume there are 12 children in all.

Which of the following code could be used to compute the total number of bars sold by the children?

for (int j=0; j<12; j++) sum += candy[j];

10
New cards

In Java, arrays are

objects

11
New cards

What does the following code do? Assume list is an array of int values, temp is some previously initialized in value, and c is an int initialized to 0.

for (j=0; j<list.length; j++)
if (list[j]<temp)c++;

It counts the number of elements in list that are less than temp

12
New cards
<p>An int array stores the following values. </p><p></p><p>Which of the following lists of numbers would accurately show the array after the first pass through the Selection Sort algorithm?</p>

An int array stores the following values.

Which of the following lists of numbers would accurately show the array after the first pass through the Selection Sort algorithm?

2, 4, 12, 9, 6, 8, 18

13
New cards

If int[] x = new int[15]; and the statement x[-1] = 0; is executed, then which of the following Exceptions is thrown?

ArrayIndexOutOfBoundsException

14
New cards

If x is a char, and values is an int array, then values[x]

casts x as an int based on x’s Unicode value for instance, if x is ‘a’ then it uses 97 and if x is ‘z’ then it uses 122)

15
New cards

To initialize a String array names to store the three Strings “Huey”, “Duey”, and “Louie”, you would do

String[] names = {“Huey”, “Duey”, “Louie”};

16
New cards

To declare a two-dimensional int array called twoD, which of the following would you use?

int[][] twoD;

17
New cards

Which of the following statements loops through every element in the ArrayList alist?

for (Object item: alist)

18
New cards

Which of the following correctly declares an ArrayList of Car objects?

ArrayList cars;

19
New cards

Which of the following expressions gives the last element in the ArrayList alist?

alist.get(alist.size()-1)

20
New cards

Which of the following statements adds item to the end of the ArrayList alist?

alist.add(item);

21
New cards
<p>Assume values is an int array that is currently filled to capacity, with the following values:<br><br>What is returned by values[3]?</p>

Assume values is an int array that is currently filled to capacity, with the following values:

What is returned by values[3]?

2

22
New cards
<p>Assume values is an int array that is currently filled to capacity, with the following values: <br><br>What is the value of values.length?</p>

Assume values is an int array that is currently filled to capacity, with the following values:

What is the value of values.length?

7

23
New cards
<p>Assume values is an int array that is currently filled to capacity, with the following values: <br><br>Which of the following loops would adequately add 1 to each element stored in values?</p>

Assume values is an int array that is currently filled to capacity, with the following values:

Which of the following loops would adequately add 1 to each element stored in values?

for (j=0; j<=values.length;j++) values[j]++;

24
New cards
<p>Assume values is an int array that is currently filled to capacity, with the following values: <br><br>The statement System.out.println(values[7]); will</p>

Assume values is an int array that is currently filled to capacity, with the following values:

The statement System.out.println(values[7]); will

cause an ArrayOutOfBoundsException to be thrown

25
New cards
<p><span>Which of the following is true with respect to A1, A2 and A3?</span></p>

Which of the following is true with respect to A1, A2 and A3?

A3 is a subclass of A2 and A2 is a subclass of A1

26
New cards
<p><span>Which of the following lists of instance data are accessible in class A2?</span></p>

Which of the following lists of instance data are accessible in class A2?

x, z, a, b

27
New cards

The instruction super(); does which of the following?

calls the constructor as defined in the current class’ parent class

28
New cards

Inheritance through an extended (derived) class supports which of the following concepts?

code reuse

29
New cards

All classes in Java are directly or indirectly subclasses of the ____ class.

Object

30
New cards

Which of the following is not a method of the Object class?

compareTo

31
New cards

Which of the following is true regarding Java classes?

All classes must have 1 parent but may have any number of children (derived or extended) classes

32
New cards

A variable declared to be of one class can later reference an extended class of that class. This variable is known as

polymorphic

33
New cards

In order to determine the type that a polymorphic variable refers to, the decision is made

by the Java run-time environment at run time

34
New cards

The relationship between a child class and a parent class is referred to as a(n) ____ relationship.

is-a

35
New cards

Consider the following recursive factorial method:

public int factorial(int x)
{
if (x>1) return x*factorial(x-1);
else return 1;

}

What is returned if factorial(3) is called?

6

36
New cards

Consider the following recursive factorial method:

public int factorial(int x)
{
if (x>1) return x*factorial(x-1);
else return 1;

}

What is returned if factorial(0) is called?

1

37
New cards

Consider the following recursive factorial method:

Consider the following recursive factorial method:

public int factorial(int x)
{
if (x>1) return x*factorial(x-1);
else return 1;

}

How many times is the factorial method invoked if originally called with factorial(5)? Include the original method call in your counting.

5

38
New cards

Consider the following recursive factorial method:

Consider the following recursive factorial method:

public int factorial(int x)
{
if (x>1) return x*factorial(x-1);
else return 1;

}

What condition defines the base case for this method?

(x > 1)

39
New cards

What is wrong with the following recursive sum method? The method is supposed to sum up the values between 1 and x (for instance, sum(5) should be 5+4+3+2+1=15)

public int sum(int x)
{
if(x==0) return 0;
else return sum(x-1)+x;
}

the base condition should be (x<=0) instead of (x==0)

40
New cards

Why is the following method one of which has infinite recursion?

public int infiniteRecursion(int n);
{
if (n>0) return infiniteRecursion(n)+1;
else return 0;
}

Because the recursive call does not move the parameter closer to the base case