🎴 Flashcard Mode

Programming Languages: C, C++, and Java

Card1 / 14
Mastered0
Review0
QuestionClick to flip

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.

AnswerClick to flip back
A
True
💡 Explanation:

This is a duplicate of blocks 129672, 129674, 129675, and 129676. TreeSet uses natural ordering; when you add Integer after String, it attempts to compare them and throws ClassCastException because Integer and String are not mutually comparable.

Change Mode