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

A TreeSet relies on natural ordering or a comparator to sort its elements. When adding elements, it compares them using compareTo(). Comparing a String to an Integer throws a ClassCastException at runtime because they are incompatible types.