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

2)

int i; for (i = 0; i

3)

int i = 0; while (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:

1) I only
2) II only
3) III only
4) I and II only
5) I, II, and III only

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:

1) I only
2) II only
3) III only
4) I, II, and III
5) I and II only

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:

1) s1
2) s1
3) s1.compareTo(s2) == -1
4) s2.compareTo(s1) > 0
5) s1.compareTo(s2) > 0

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.
2) 4
3) 5
4) 6
5) 7

!((x > y) && (y

I. !(x > y) || !(y y) && !(y 0)

Question 5 options:

1) I only
2) II only
3) III only
4) I and III only
5) II and III only

Polymorphism occurs at: (1 point)

Question 8 options:

1) compile time
2) run time
3) debug time
4) early binding time
5) None of the above

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!