Logo Passei Direto
Buscar
Material
páginas com resultados encontrados.
páginas com resultados encontrados.

Prévia do material em texto

Certified Java Programmer Mock Exam 90
} 
class J { 
 public static void m1(I i) {i = null;} 
 public static void main (String[] args) { 
 I i = new I("X"); // 1 
 m1(i); // 2 
 System.out.print(i.name()); // 3 
 } 
} 
Which of the following are true statements and which of the following could be a result of attempting to compile and run the program? 
a. The object created a line 1 is eligible for garbage collection after line 2. 
b. A NullPointerException is generated at line 3. 
c. Prints X. 
d. Compiler error. 
e. None of the above. 
Capítulo 8 – Garbage Collection (Opcionais) 
 
Question 1 
import java.util.*; 
class A { 
 private static int notFinalized; 
 public static int notFinalized() {return notFinalized;} 
 private static ArrayList finalizedNames = new ArrayList(); 
 public static Iterator finalizedNames() { 
 return finalizedNames.iterator(); 
 } 
 private String name; 
 public A(String s) {name = s; notFinalized++;} 
 public void finalize() { 
 finalizedNames.add(name); 
 notFinalized--; 
 } 
} 
class F { 
 public static void main(String[] args) { 
 A x1 = new A("X"); 
 A y1 = new A("Y"); 
 x1= null; 
 y1 = null; 
 System.gc(); 
 while (A.notFinalized() > 0) { 
 try {Thread.sleep(1000);} catch (InterruptedException ie) {} 
 } 
 Iterator i = A.finalizedNames(); 
 while (i.hasNext()) { 
 System.out.print(i.next()); 
 } 
 } 
} 
Which of the following are true statements and which of the following could be a result of attempting to compile and run the program? 
a. Prints: XY 
b. Prints: YX 
c. Prints: XXYY 
d. Prints: YYXX 
e. Nothing is printed. 
f. There is no guarantee that the garbage collector will run. 
g. There is no guarantee that F.main will run to completion. 
h. Compiler Error. 
i. Run Time Error. 
j. None of the above. 
 
Question 2 
class J { 
 private static int notFinalized; 
 public static int notFinalized() {return notFinalized;} 
 private K k; 
 private int name; 
 public int name() {return name;} 
 public J(K k, int i) {this.k = k; name = i; notFinalized++;} 
 public void finalize() { 
 synchronized (k) { 
 System.out.print(name); 
 notFinalized--; 
 k.notify(); 
 } 
 }

Mais conteúdos dessa disciplina