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

This is a duplicate of blocks 129672, 129674, and 129675. TreeSet maintains sorted order and requires mutually comparable elements. Adding Integer after String causes ClassCastException during the comparison operation at insertion time.

AI explanation

Just like any other TreeSet, this collection maintains sorted order and needs elements to be mutually comparable. Mixing a String and an Integer means the set cannot determine ordering between them, so attempting to add the second, differently-typed element triggers a ClassCastException.