I was taking a mock exam on javabeat.com and got stumped by the first 5 questions , all of them were about collections and were programs. I had did my prepearation based on Kathy Sierra book and in it says we need not know in detail about collections. Anyway listed below is one of the question I faced, don't think from the theory I read I can answer this question...
Will the actual exam contain this kind of questions ??
If so can someone point me to some reading materials so that I can be prepared for such questions ?
import java.util.*;
public class Test1{
public static void main(
String a[]){
Set s = new TreeSet();
s.add(new Person(20));
s.add(new Person(10));
System.out.println(s);
}
}
class Person{
Person(int i){}
}
What is the output?
A1 10 20
A2 ClassCastException
A3 Compiler Error
A4 Compiler Error
Answer is A2. ClassCastException
Cheers,
JP