Multiple Choice Question

Quiz Guidelines

 

QID: 
455
Question: 

What will the following class print when compiled and run?

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;
}
}

Select 1 option

A. It will not compile because 'a' is final.
B. It will not compile because method setIt() cannot change x.link.
C. It will print 5, 10.
D. It will print 10, 10.
E. It will throw an exception when run.

Q&A Set: 

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!