1. Evaluate the following Java expression, if x=3, y=5, and z=10:
2. Whenever the first number is smaller than the second, the remainder is the second number.
3. The following code prints 135.
4. Assume that SomeClass and MainClass are properly defined in separate files. What is the output of main()?
5. The above code gives error that ____________________________ with a call to the SomeClass constructor.
6. Refer to the following code. If there were curly braces around the two indented statements, then:
8. Given this code, which of the following will cause an infinite loop? Assume temp is an int variable initialized to be greater than zero and that a is an array of ints.
9. If nums has been created as an ArrayList object and initially contains integer values: [0, 0, 4, 2, 5, 0, 3, 0], what will nums contain as a result of executing method numQuest?
private List nums;
//precondition: nums.size() > 0
//nums contains Integer objects
public void numQuest() {
int k = 0;
Integer zero = new Integer(0);
while (k < nums.size()) {
if (nums.get(k).equals(zero))
nums.remove(k);
k++;
}
}
[4, 2, 5, 3]
[0, 4, 2, 5, 3]
[0, 0, 4, 2, 5, 0, 3, 0]
[3, 5, 2, 4, 0, 0, 0, 0]
10. What is the output of the following program?
11. What needs to go on line 7 in order for the code to print: 101 Adam
12. What is the output of the following program?
13. The output of the following program is 120.
14. What is the output of the following program?
public class MyFirst {
public static void main(String[] args) {
MyFirst obj = new MyFirst(n);
}
static int a = 10;
static int n;
int b = 5;
int c;
public MyFirst(int m) {
System.out.println(a + ", " + b + ", " + c + ", " + n + ", " + m);
}
// Instance Block
{
b = 30;
n = 20;
}
// Static Block
static
{
a = 60;
}
}
10, 5, 0, 20, 0
60, 5, 0, 20
60, 30, 0, 20, 0
10, 30, 20
15. ABH8097 would be considered a valid long literal.