| 9. | What will be the output of the program? class Test |
|||||||
Answer: Option C Explanation: In the first two iterations x is incremented once and y is not because of the short circuit && operator. In the third and forth iterations x and y are each incremented, and in the fifth iteration x is doubly incremented and y is incremented. |
| 10. | What will be the output of the program? class Test |
|||||||
Answer: Option B Explanation: This is an example of a nested ternary operator. The second evaluation (x < 22) is true, so the "tiny" value is assigned to sup. |
| 11. | What will be the output of the program? class Equals |
|||||||
Answer: Option C Explanation: The code will not compile because in line 7, the line will work only if we use (x==y) in the line. The == operator compares values to produce a boolean, whereas the = operator assigns a value to variables. Option A, B, and D are incorrect because the code does not get as far as compiling. If we corrected this code, the output would be false. |
| 12. | What will be the output of the program? class BitShift |
|||||||
Answer: Option A Explanation: Option A is correct. The >>> operator moves all bits to the right, zero filling the left bits. The bit transformation looks like this: Before: 1000 0000 0000 0000 0000 0000 0000 0000 After: 0000 0000 0000 0000 0000 0000 0000 0001 Option C is incorrect because the >>> operator zero fills the left bits, which in this case changes the sign of x, as shown. Option B is incorrect because the output method print() always displays integers in base 10. Option D is incorrect because this is the reverse order of the two output numbers. |
| 13. | What will be the output of the program? class PassS void start() String fix(String s1) |
|||||||
Answer: Option D Explanation: When the fix() method is first entered, start()'s s1 and fix()'s s1 reference variables both refer to the same String object (with a value of "slip"). Fix()'s s1 is reassigned to a new object that is created when the concatenation occurs (this second String object has a value of "slipstream"). When the program returns to start(), another String object is created, referred to by s2 and with a value of "stream". |
| 14. | What will be the output of the program? class Test void start() boolean fix(boolean b1) |
|||||||
Answer: Option B Explanation: The boolean b1 in the fix() method is a different boolean than the b1 in the start() method. The b1 in the start() method is not updated by the fix() method. |
| 15. | What will be the output of the program? class PassA void start() long [] fix(long [] a3) |
|||||||
Answer: Option B Explanation: Output: 15 15 The reference variables a1 and a3 refer to the same long array object. When the [1] element is updated in the fix() method, it is updating the array referred to by a1. The reference variable a2 refers to the same array object. So Output: 3+7+5+" "3+7+5 Output: 15 15 Because Numeric values will be added |
