1. What are the values of x, y, and z after the following code executes?
2. When a double is converted into an integer in Java, it truncates the digits after the decimal. The ouput here is therefore 9.
3. Assume that Class1 and MainClass are properly defined in separate files. What is the output of the code in main()?
4. A method called palindrome checks to see if a string is the same forwards and backwards. What advantage does Data Set A have over Data Set B for testing?
5. Given the following code segment, what is the value of s1 after the code executes?
6. The reason for the above answer (assumign you got it right!) is because:
7. What is the output from the following code?
8. Which of the following is equivalent to the code segment below?
9. What is printed as a result of the following code segment?
10. Which of the following preconditions is reasonable for the Liquid constructor?
11. Consider the following field arr and method checkArray. Which of the following best describes what checkArray returns?
12. Which of the following best explains why the getAge method does NOT work as intended?
13. What is printed as a result of executing the following code segment?
List aList = new ArrayList();
aList.add(new Integer(1));
aList.add(new Integer(2));
aList.add(1, new Integer(5));
aList.set(1, new Integer(4));
aList.add(new Integer(6));
aList.add(new Integer(3));
System.out.println(aList);
[1, 2, 4, 6, 3]
[1, 2, 5, 4, 6, 3]
[6, 5, 4, 3, 2, 1]
[1, 4, 2, 6, 3]
14. Consider the following code segment. The value of sum after this code executes is 6.
int[][] m = { {1,1,1,1},{1,2,3,4},{2,2,2,2},{2,4,6,8}};
int sum = 0;
for (int k = 0; k < m.length; k++) {
sum = sum + m[m.length-1-k][1];
}
TRUE
FALSE
15. Given the following, which of the following is a correct call to method1?
16. Given the following class declarations, the output from Student s1 = new HungryStudent(); followed by s1.getInfo(); will be: Pie,Strawberry Pie
17. The output of the following code is: [1, 4, 5]
18. Given the following method declaration, which of the following is printed as the result of the call whatsup(1234)?
19. In the above recursive code, the method calls itself when:
20. Given the following method declaration, what value is returned as the result of the call guess(5)?