Multiple choice technology programming languages

1.Set s = new TreeSet(); 2.s.add("JAVA"); 3.s.add(new Integer(5)); Line 3 will give ClassCast Exception because Two different types of object are getting added.

  1. True

  2. False

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

TreeSet maintains natural ordering and requires elements to be mutually comparable. When you add a String (JAVA) then an Integer (5), line 3 triggers ClassCastException at add() time because TreeSet tries to compare Integer with String to determine position, and they're not comparable. HashSet (block 129673) doesn't sort, so no exception.