Wednesday, May 30, 2007

Answers of "SCJP 310-035 Sample Questions (1)"

Click here for original questions:
SCJP 310-035 Sample Questions (1)


1) A, B, D. The angle-bracket notation is part of release 5.0's generic collections. See Chapter 6for more information.

2) B, D. All the choices are valid method signatures. However, in order to be the entry point of an application, a main() method must be public, static, and void; it must take a single argument of type String[].

3) C. In this code, the optional result values for the conditional operator, 99.99 (a double) and 9 (an int), are of different types. The result type of a conditional operator must be fully determined at compile time, and in this case the type chosen, using the rules of promotion for binary operands, is double. Because the result is a double, the output value is printed in a floatingpoint format. If the two possible argument types had been entirely incompatible, for example, (x > 4) ? "Hello" : then the compiler would have issued an error at that line.

4) C, D. If a class does not provide implementations for all methods of all interfaces that the class declares it implements, that class must be declared abstract. Abstract classes may not be instantiated.

5) C. When a numeric primitive is cast or converted to a wider type, the original value is preserved, so naturally the original sign cannot change.

6) E, F. The Cat class is a subclass of the Pet class, and as such should extend Pet, rather than contain an instance of Pet. B and C should be members of the Pet class and as such are inherited into the Cat class; therefore, they should not be declared in the Cat class. D would declare a reference to an instance of the Cat class, which is not generally appropriate inside the Cat class (unless, perhaps, you were asked to give the Cat a member that refers to its mother). Finally, the neutered flag and markings descriptions, E and F, are the items called for by the specification; these are correct items.

7) A. The Runnable interface defines a run() method with void return type and no parameters. The method given in the problem has a String parameter, so the compiler will complain that class Greebo does not define void run() from interface Runnable. B is wrong, because you can definitely pass a parameter to a thread¡¯s constructor; the parameter becomes the thread¡¯s target. C, D, and E are nonsense.

8) A. The StringBuffer class is mutable. After execution of line 2, sbuf refers to the same object, although the object has been modified.

9) D. Default serialization is bypassed only if the writeObject() method has private access.

10) A, C. All exceptions declared by an overriding method must be compatible with types thrown by the overridden version.


Latest Posts