Question 24
The reason that II and III can be added to the class without creating a compile time error is because they are new methods with new signatures. In the case of I that method it’s actually a change to an existing method so everything that uses that class would need to be recompiled.
Question 34
The “expression” code to set the sizeOfList int variable should be “listOfWords.size()” instead This sets the sizeOfList variable to the true number of instances in the list. The condition code of k != sizeOfList - 1 would not work with the length set differently for answer choice C. Given the “expression” code is set the way that it is, the “condition” code is set check for the variable sizeOfList -1. This is important because the for loop starts at k = 0.
Question 36
Binary search when implemented correctly eliminates half of the array each iteration, so it should take 11 iterations.
Question 37
Option III apparently works, even though it is messy and not as easy as it could be. The first loop only works because this loop will process three times before (k <= words.length / 2). First pass Length is 5 - 0 - 1 = 4. Variable “temp” assigns “Car” to it. Next pass 5 - 1 - 1 = 3 Variable “temp” appends “House” to it. Next pass 5 - 2 - 1 = 2 Variable “temp” appends “Gorilla” to it. Second for loop copies over each slot in the temp array into the result array and then we return the result array.
Question 39
I just reversed the lines of the output. When calling the “set” method on the students list the element that previously existed at the specified index is returned. This is why the first output that you see is “Bob” when it’s replaced with “Alex” and “Carl” when it’s replaced with “Alex”. When the second “for” block executes, the array is now populated with “Alex Alex Alex” from the previous “for” block so it will print out “Alex Alex Alex”.