Question: Question 17 (12 points) Saved When the following code is run, which of the following exceptions could occur if the precondition is met? (2 points)

Question 17 (12 points)

Saved

When the following code is run, which of the following exceptions could occur if the precondition is met? (2 points)

// precondition: a is NOT null public String doSomething(ArrayList a, int b) { int i; String s;

for(i = 0; i < a.size(); i++) { s = (String)(a.get(i)); if(s.length() == b) { return s; } } return null; }

Question 17 options:

1)

ArithmeticException

2)

ArrayIndexOutOfBoundsException

3)

ClassCastException

4)

IndexOutOfBoundsException

5)

NullPointerException

Question 18 (12 points)

Saved

Assume a two-dimensional array is declared as follows:

int arr[][] = {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12};

Which of these statements are true? (2 points)

I. arr.length is 3 II. arr[0].length is 4 III. arr[2][3] is 12

Question 18 options:

1)

I only

2)

II only

3)

III only

4)

I and III only

5)

I, II, and III

Question 19 (12 points)

Saved

What is stored in the array arr after the following code executes? (2 points)

int[ ] arr = {17, 34, 43, 71}; int i = 0; while(i < arr.length) { if((arr[i] % 2) == 1) { arr[i] = arr[i] % 3; } else { arr[i] = arr[i] / 3; } i++; }

Question 19 options:

1)

{1, 11, 2, 10}

2)

{2, 10, 11, 1}

3)

{2, 11, 1, 2}

4)

{2, 11, 1, 10}

5)

An ArrayIndexOutOfBoundsException occurs.

Question 20 (12 points)

Saved

Suppose you write a subclass of Insect named Ant. You add a new method named doSomething to the Ant class. You write a client class that instantiates an Antobject and invokes the doSomething method. Which of the following Antdeclarations will permit this? (2 points)

I. Insect a = new Ant(); II. Ant a = new Ant(); III. Ant a = new Insect();

Question 20 options:

1)

I only

2)

II only

3)

III only

4)

I and II only

5)

I, II, and III only

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!