Java Reference
In-Depth Information
15. What is the output of the following code?
1. public class FinalTest {
2.
3. public static void main(String [] args) {
4. House h = new House();
5. h.address = “123 Main Street”;
6. h = null;
7. System.gc();
8. }
9. }
10.
11. class House {
12. public String address;
13.
14. public void finalize() {
15. System.out.println(“Inside House”);
16. address = null;
17. }
18. }
A. There is no output.
B. Inside House
C. The output cannot be determined.
D. The code generates a compiler error.
16. Given the following class named House, which of the following statements is true? (Select
two answers.)
1. public class House {
2. public String address = new String();
3.
4. public void finalize() {
5. System.out.println(“Inside House”);
6. address = null;
7. }
8. }
A. “Inside House” is displayed just before a House object is garbage collected.
B. “Inside House” is displayed twice just before a House object is garbage collected.
C. The finalize method on line 4 never actually gets called.
D. There is no need to assign address to null on line 6.
E. The String object from line 2 is guaranteed to be garbage collected after its corre-
sponding House object is garbage collected.
Search WWH ::




Custom Search