Multiple choice technology web technology

Given: public static void before() { Set set = new TreeSet(); set.add("2"); set.add(3); set.add("1"); Iterator it = set.iterator(); while (it.hasNext()) System.out.print(it.next() + " "); } Which statements are true?

  1. The before() method will print 1 2

  2. The before() method will print 1 2 3

  3. The before() method will print three numbers, but the order cannot be determined

  4. The before() method will not compile

  5. The before() method will throw an exception at runtime

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

The code mixes String objects ("2", "1") with Integer object (3) in a TreeSet without generics. TreeSet orders elements using compareTo, which throws ClassCastException when comparing incompatible types like String and Integer at runtime. Compilation succeeds due to raw type.