Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

New Trends In Databases And Information Systems Adbis 2019 Short Papers Workshops Bbigap Qauca Sembdm Simpda M2p Madeisd And Doctoral Consortium Bled Slovenia September 8 11 2019 Proceedings

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Robert Wrembel ,Mirjana Ivanovic ,Johann Gamper ,Mikolaj Morzy ,Theodoros Tzouramanis ,Jerome Darmont

1st Edition

3030302776, 978-3030302771

Students also viewed these Databases questions