Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.54 :

Posted: Wed Jul 27, 2011 2:50 pm
by ETS User
In the following program how y.link is null?
class Holder
{
int value = 1;
Holder link;
public Holder(int val){ this.value = val; }
public static void main(String[] args)
{
final Holder a = new Holder(5);
Holder b = new Holder(10);
a.link = b;
b.link = setIt(a, b);
System.out.println(a.link.value+" "+b.link.value);
}

public static Holder setIt(final Holder x, final Holder y)
{
x.link = y.link;
return x;
}

}
Can somebody explain me please?

Re: About Question com.enthuware.ets.scjp.v6.2.54 :

Posted: Sat Jan 26, 2013 12:54 pm
by Anu
Because ,

(a.link or x.link) and (b.link or y.link) are just Holder objects that
are not instantiated anywhere in the code. So they are null.

Hope that helps :roll:

Good Luck!