I got it from
http://www.danchisholm.net/oct1/mybook/chapter16/exam1.html class B {
private
String name;
public B(String name) {this.name = name;}
public String toString() {return name;}
protected void finalize() {System.out.print(name);}
}
class H {
static B ba = new B("Ba");
static int i = 1;
static B m1(B b) {return b = new B("B" + i++);}
public static void main (String[] args) {
B x = m1(ba); m1(x);
System.out.println(", " + ba + ", " + x);
}}
Which of the following could be a result of attempting to compile and run the program?
a. Ba, B1, B2
b. B1, Ba, B2
c. , Ba, B1
d. B2, Ba, B1
e. BaB1b2, null, null
f. B1B2, ba, null
Answer is c, d
here i can understand option c.
But for option d, i assume that method finalize will run even if we dont call System.gc. But If I assume so then why option a and b are not correct because it may run in any order(for any object).please clear my doubt
Thanks,
Geeta Vemula