Sunday, February 10, 2008

Answers of Practice Questions

Solutions:


Answer 1
b is the correct answer. Like static methods, member variables are also computed using the type of the reference.
Answer 2
a, d & e are the correct answers. These are the names of interfaces.
Answer 3
b is the correct answer. File object represents a filename, not a physical file, and not in charge on creating files.
Answer 4
c is the correct answer. i variable is declared in a for block, and therefore can�t be used in line 8 � outside that block.
Answer 5
a is the correct answer. The intern method in the String class makes the system search for a pre-existing String object with a given content.
Answer 6
a is the correct answer. The inner class is written perfectly correct. This block of code will call the doAction() when button is clicked.
Answer 7
b & d are the correct answers. d is correct because exceptions obey a hierarchy just like other objects. Answer d is correct because these exceptions descend from RuntimeException, so they don�t have to be declared.
Answer 8
a, c & e are the correct answers. Those methods can be overridden by the programmer in order to create an Applet.
Answer 9
c, d & e are the correct answers. The call to super() constructor must be first statement in constructor. Therefore compiler can�t find a legal call to super constructor and adds its own one � to the constructor that accepts no parameters, that can�t be found in a super class. Finally, after casting Oharada object to Vapenka variable field nationality can�t be accessed.
Answer 10
b is the correct answer. 27 is an int by default. In line 2 casting is done by the compiler, in line 4 the compiler will demand an implicit casting.
Answer 11
b, d & e are the correct answers. The reference, stored in flag variable can�t be changed because it is final. The check (||) can�t be applied on primitive and object simultaneously. You don�t have to use a Boolean object to get String representative of a boolean primitive. It is more convenient to use a static method in Boolean class, that doesn�t require a Boolean object.
Answer 12
c is the correct answer. When applied to primitives, the == sign checks the equality of a value, but when applied to objects, it checks the equality of a reference, not a value.
Answer 13
a & e are the correct answers. a is correct because local variable can be garbage collected after the program exits the block that contains the variable. e is correct because once the reference to local variable stored in object which scope lasts beyond the local block it can�t be garbage collected.
Answer 14
a, c & e are the correct answers. b and d are incorrect because the overriding method can throw less exceptions, in term that they are the same, or subclasses of those which where thrown is original method, or no exceptions at all.
Answer 15
c is the correct answer. RandomAccessFile stands outside other Java IO hierarchies and derives directly from Object.

No comments: