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:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
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:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
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:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
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:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started