Prévia do material em texto
Certified Java Programmer Mock Exam 91
}
class K {
private void m1() {
J j = null;
for (int i = 0; i 0) {
try {wait();} catch (InterruptedException ie) {}
}
}
}
public static void main(String[] args) {
new K().m1();
}
}
When the processing of line 2 begins how many objects of type J that were created at line 1 are eligible for garbage collection?
a. 0
b. 1
c. 4
d. 5
e. Can not be determined without more information.
f. Compiler error.
g. Run time error.
h. None of the above.
Question 3
class Arnold {
private H h;
private String quote;
public String quote() {return quote;}
private static int notFinalized;
public static int notFinalized() {return notFinalized;}
public Arnold(H h, String s) {this.h = h; quote = s; notFinalized++;}
public void finalize() {
synchronized (h) {
notFinalized--;
h.arnold(this);
h.notify();
}
}
}
class H {
private Arnold arnold;
public void arnold(Arnold a) {arnold = a;}
public void m1() {
arnold = new Arnold(this, "I'll be back!");
arnold = null;
System.gc();
synchronized (this) {
while (Arnold.notFinalized() > 0) {
try {wait();} catch (InterruptedException ie) {}
}
}
System.out.print(arnold.quote()); // 1
}
public static void main(String[] args) {new H().m1();}
}
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. A finalizer-reachable or finalizable (also known as resurrectable) object can never become reachable again.
b. NullPointerException is thrown at line 1.
c. Prints: I'll be back!
d. Prints nothing.
e. Compiler error.
f. Run time error.
g. None of the above.
Question 4
class I {
private static int notFinalized;
public static int notFinalized() {return notFinalized;}
private J observer;
private I other;
public void other(I i) {other = i;}
private String name;
public String name() {return name;}