Question: Question 21 (12 points) Saved Consider the following code: String[] fruits = {apple, pear, mango, peach}; int i = 3; String str = p; for(String
Question 21 (12 points)
Saved
Consider the following code:
String[] fruits = {"apple", "pear", "mango", "peach"}; int i = 3; String str = "p";
for(String item : fruits) { i = item.indexOf("p") + 2; str += item.substring(i); }
System.out.println(str);
Assume that the loop accesses array elements in order. What is output by this code? (2 points)
Question 21 options:
|
|
| ||
|
|
| ||
|
|
| ||
|
|
| ||
|
|
|
Question 22 (12 points)
Saved
Consider the following code:
int[] arr = new int[ < some positive integer > ]; int index;
// assume arr is filled with values here // assume the user enters a value for index here
if((index >= 0) && (index <= arr.length)) { System.out.println(arr[index]); }
When could this code throw an exception? (2 points)
Question 22 options:
|
|
| ||
|
|
| ||
|
|
| ||
|
|
| ||
|
|
|
Question 23 (12 points)
Saved
Consider the following class descriptions and code. Account is an abstract class with one abstract method named getInterestRate. BasicCheckingAccount is a concrete class that extends Account. EnhancedCheckingAccount extends BasicCheckingAccount and overrides getInterestRate.
Account acct; double rate1, rate2; acct = new BasicCheckingAccount(< parameters not shown >); rate1 = acct.getInterestRate(); // assignment 1 acct = new EnhancedCheckingAccount(< parameters not shown >); rate2 = acct.getInterestRate(); // assignment 2
The reference to getInterestRate in assignment 2 is to the class (2 points)
Question 23 options:
|
|
| ||
|
|
| ||
|
|
| ||
|
|
| ||
|
|
|
Question 24 (12 points)
Saved
Consider a method that compares the elements of two ArrayLists and returns the value true if the elements in corresponding positions are equal, and returns falseotherwise.
Which of the following code will accomplish this? (2 points)
Question 24 options:
|
|
| ||
|
|
| ||
|
|
| ||
|
|
| ||
|
|
|
Question 25 (12 points)
Assume table has been declared and initialized as a two-dimensional integer array with 9 rows and 5 columns. Which segment of code will correctly find the sum of the elements in the fifth column? (2 points)
Question 25 options:
|
|
| ||
|
|
| ||
|
|
| ||
|
|
| ||
|
|
|
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
