| 8.1 | Which statement is true? Select the one correct answer. -
Objects can be explicitly destroyed using the keyword delete . -
An object will be garbage collected immediately after it becomes unreachable. -
If object obj1 is accessible from object obj2, and object obj2 is accessible from obj1 , then obj1 and obj2 are not eligible for garbage collection. -
Once an object has become eligible for garbage collection, it will remain eligible until it is destroyed. -
If object obj1 can access object obj2 that is eligible for garbage collection, then obj1 is also eligible for garbage collection. |
| 8.2 | Identify the location in the following program where the object, initially referenced with arg1 , is eligible for garbage collection. public class MyClass { public static void main(String[] args) { String msg; String pre = "This program was called with "; String post = " as first argument."; String arg1 = new String((args.length > 0) ? "'" + args[ 0 ] + "'" : "<no argument>"); msg = arg1; arg1 = null; // (1) msg = pre + msg + post; // (2) pre = null; // (3) System.out.println(msg); msg = null; // (4) post = null; // (5) args = null; // (6) } } Select the one correct answer. -
After the line labeled (1). -
After the line labeled (2). -
After the line labeled (3). -
After the line labeled (4). -
After the line labeled (5). -
After the line labeled (6). |
| 8.3 | Which statement is true? Select the one correct answer. -
If an exception is thrown during the execution of the finalize() method of an eligible object, then the exception is ignored and the object is destroyed. -
All objects have a finalize() method. -
Objects can be destroyed by explicitly calling the finalize() method. -
The finalize() method can be declared with any accessibility. -
The compiler will fail to compile code that defines an overriding finalize() method that does not explicitly call the overridden finalize() method from the superclass. |
| 8.4 | Which statement is true? Select the one correct answer. -
The compiler will fail to compile code that explicitly tries to call the finalize() method. -
The finalize() method must be declared with protected accessibility. -
An overriding finalize() method in any class can always throw checked exceptions. -
The finalize() method can be overloaded. -
The body of the finalize() method can only access other objects that are eligible for garbage collection. |
| 8.5 | Which statement describes guaranteed behavior of the garbage collection and finalization mechanisms? Select the one correct answer. -
Objects will not be destroyed until they have no references to them. -
The finalize() method will never be called more than once on an object. -
An object eligible for garbage collection will eventually be destroyed by the garbage collector. -
If object A became eligible for garbage collection before object B , then object A will be destroyed before object B . -
An object, once eligible for garbage collection, can never become accessible by a live thread. |