| No. | Answer | Remark | |
|---|---|---|---|
| 1 | b e g h k | goto new finally const do | |
| 2 | b | Prints: null | The System.out.print method prints the word null if the argument is a String reference that is null. |
| 3 | a b | abstract public | The modifier, abstract, is applicable to an interface declaration, but its use is strongly discouraged; because every interface is implicitly abstract. If an interface is declare public, then the compiler will generate an error if the class is not stored in a file that has the same name as the interface plus the extension .java. The modifier, static, is applicable to a member interface, but not to an interface that is not nested. The modifier, synchronized, is applicable only to concrete implementations of methods. The modifiers, transient and volatile, are applicable only to variables. |
| 4 | b d f | 0x0000 to 0xffff 0 to 0177777 0 to 65535 | A char is a 16 bit unsigned value; so none of the char values are negative and the minimum value is zero. The maximum value is 216. |
| 5 | d | Prints: true,true | The sign of an integral numeric type is changed by inverting all of the bits and by adding one. |
| 6 | c d | 3 4 | This question demonstrates a variety of assignment conversions. The compiler will implicitly do a narrowing conversion for an assignment statement if the right hand operand is a compile time constant of type byte, short, char, or int and the value falls within the range of the variable on the left and if the variable on the left is of type byte, short, or char. In this case, variables s1 and c1 are not compile time constants so the compiler will not do an implicit narrowing conversion. However, variables s2 and c2 are compile time constants that fall within the range of the left hand operand. For more information, please see JLS section 5.2. |
| 7 | c | The internal data model can be read and modified only through accessor and mutator methods. | A class is not tightly encapsulated if the internal data model can be read and/or modified without working through accessor (i.e. get) and mutator (i.e. set) methods. |
| 8 | d | InterruptedException |
The methods
|
| 9 | b | Prints: A B C | The String instance referenced by s2 is passed to the m1 method by passing the value of the reference. The reference value used in method m1 is a local copy of the reference. If the local copy used in method m1 is changed, then the original reference variable in the main method remains unchanged. |
| 10 | b | Compile-time error at 1 |
At line 1, the invocation of the
|
| 11 | c | Compile-time error |
The
|
| 12 | g | Prints: true,true,false |
|
| 13 | b d e | Long.parseLong("1L") Long.parseLong("0x10") Long.parseLong("1.0") |
|
| 14 | g | valueOf | |
| 15 | c | TreeSet | The elements are not key/value pairs; so a Map is not a good choice. A List generally accepts duplicate elements. A Set stores a collection of unique objects; so any attempt to store a duplicate object is rejected. TreeSet stores elements in an order that is determined either by a Comparator or by the Comparable interface. |
| 16 | d | Prints: false,true,true | HashSet implements the Set interface, but not the Map interface. HashMap extends AbstractMap and implements the Map interface. Hashtable extends Dictionary and implements the Map interface. |
| 17 | a b c d | java.lang.Byte java.lang.Integer java.util.Vector java.lang.String | The wrapper classes and the collection classes override the equals and hashCode methods. The String class overrides the equals and hashCode methods, but StringBuffer does not. |
| 18 | e | 5 | The synchronized modifier is a method modifier and can not be applied to a field. |
| 19 | d e | In this code example a throw statement must be used in place of the assert statement. Compile-time error | If the default label of a switch statement should not be reached under normal operating circumstances, then the default case becomes a good candidate for the use of an assert statement. If a method is declared with a non-void return type and if no return statement appears after the switch statement, then each case of the switch must have a return statement or a throw statement. The throw statement is used rather than an assert, because the compiler knows that the assert statement is not functional when assertions are disabled. |
| 20 | a | 1 | Please note that this question asks which objects are NOT eligible for garbage collection after method m1 returns. After method m1 returns, the array a1 created on line 1 is not eligible for garbage collection. Method m1 sets all elements of the array to null; so the objects created on lines 2, 3 and 4 are eligible for garbage collection when method m1 returns. |
| 21 | f | Compile-time error at line 4. | Anytime a field is accessed from within a static context it is very important to verify that the field is also static. If the field is instead an instance variable then the result is a Compile-time error. |
| 22 | d | Prints: GFC206,GFC206 | Type GFC207 is a subclass of types GFC206 and GFC205, so any of the four methods are applicable to the method invocation expression, m(gfc207, gfc207). The most specific of the four, m(GFC206 x, GFC206 y), is chosen. Type GFC206 is a subclass of type GFC205, and method m(GFC206 x, GFC206 y) is more specific than the other three, because any invocation of m(GFC206 x, GFC206 y) could also be handled by any of the other three without causing a compile-time type error. |
| 23 | a | Prints: ABCI | Suppose that a class extends a superclass, X, or implements an interface, X. The field access expression ((X)this).hiddenField is used to access the hidden field, hiddenField, that is accessible within the superclass or interface, X. |
| 24 | d | G.this.s1 | The qualified this expression ClassName.this.name can be used to access shadowed variables declared within an enclosing class. |
| 25 | d | Compile-time error | The declarations of b1 and c1 cause compile-time errors, because a reference of a subclass type can not refer to an instance of the superclass type. |
| 26 | d | Prints: 1,2,3,4,5,3 | The expression can be simplified as follows: j = 1 + ((2 * 3) % 4) + 5 = 8. The original expression is as follows: j = ++i + ++i * ++i % ++i + ++i. Step one. Evaluate the unary expressions from left to right: j = 1 + 2 * 3 % 4 + 5. Step two. Add parentheses to indicate operator precedence: j = 1 + ((2 * 3) % 4) + 5. Step three. Evaluate the inner most parentheses: j = 1 + (6 % 4) + 5. Repeat step three: j = 1 + 2 + 5. Repeat step three: j = 8. The argument of the print expression is: j%5. The result is: 8 % 5 = 3. |
| 27 | d | Prints: 3,1 | Inside of method m2, the local variables i1 and i2 remain unchanged while the shadowed instance variables are changed. |
| 28 | a k | Prints: null Run-time error | The declaration A13[] a1 = new A13[1] declares a variable a1 that references an array that contains one component of type A13. The declaration A13[][] a2 = new A13[2][1] declares a variable a2 that references an array that contains two components of type A13[]. In other words, the array referenced by a2 contains two references to two subarrays of type A13[]. The size of each subarray is 1. The declaration A13[][][] a3 = new A13[3][3][3] declares a variable a3 that references an array that contains three components of type A13[][]. In other words, the array referenced by a3 contains three references to three subarrays of type A13[][]. The dimensions of the subarrays are 3 X 3. The dimensions of the array referenced by a3 are 3 X 3 X 3. The number of elements in the array referenced by a3 is 3 * 3 * 3 = 27 elements. Each of the three subarrays contains three components, where each is a reference to a subarray of type A13[]. Each of the 27 elements of the array referenced by a3 is a reference of type A13 that has been initialized to the default value of null. At line 7, a reference to the array referenced by a2 is assigned to each of the three components of the array referenced by a3, a3[0] = a3[1] = a3[2] = a2. Since the array referenced by a2 has dimensions 2 X 1, the array referenced by a3 now has dimensions 3 X 2 X 1. The number of elements is 6. An attempt to access any element beyond those 6 results in an exception at run-time. |