Question: 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
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 false otherwise.
Which of the following code will accomplish this? (2 points)
Question 25 options:
| | | 1) | boolean temp = false; int i; for (i = 0; i | |
| | |
| | |
| | | 4) | boolean temp = true; int i; for (i = 0; i | |
| | | 5) | int i = 0; while (i a.size()) { return true; } return false; | |
Suppose that you have an ArrayList and that it contains String objects. Which declaration of the ArrayList does not require that objects retrieved using the get method be cast to Strings before calling a Stringmethod? (2 points)
Question 26 options:
Which of the following lines of code could not be used to store a random number between 1 and 6, inclusive, into the variable dice? (2 points)
I. int dice = Math.random(6); II. int dice = Math.random(6) + 1; III. int dice = (int)(Math.random() * 6) + 1;
Question 27 options:
Consider the following code:
public class MyClass { private int secret; public int getSecret(){ return secret; } }
Is the instance variable secret really private, meaning that it cannot be cannot be changed by client code? (2 points)
Question 28 options:
| | | 1) | Yes, because it is private. | |
| | | 2) | Yes, because it is private and non static. | |
| | | 3) | No, because getSecret() returns a reference to secret, which allows direct access to the instance variable. | |
| | | 4) | No, because getSecret() returns the value of secret, which can be changed by the client. | |
| | | 5) | No, because MyClass is a public class, and so its instance variables are all accessible by outsideclasses. | |
Which of the following boolean expressions correctly determines that String s2 is greater than String s1 in logical order? (2 points)
Question 3 options:
| | |
| | |
| | | 3) | s1.compareTo(s2) == -1 | |
| | |
| | |
Suppose the following array is declared: int[] numbers = {4, 5, 6, 7}; and the following integer is declared: int index = 1 + 6 % 2 * 2;
What is the value of numbers[index]? (2 points)
Question 4 options:
| | | 1) | An ArrayIndexOutOfBoundsException occurs. | |
| | |
| | |
| | |
| | |
!((x > y) && (y
I. !(x > y) || !(y y) && !(y 0)
Question 5 options:
Polymorphism occurs at: (1 point)
Question 8 options: