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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

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

Post 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?

Anu

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

Post 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!

Post Reply

Who is online

Users browsing this forum: No registered users and 208 guests