Multiple choice technology programming languages

1.Set s = new HashSet(); 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
B Correct answer
Explanation

A HashSet in Java does not require elements to be mutually comparable. It uses hashCode() and equals() to manage elements, so adding a String and an Integer is perfectly legal and will not throw a ClassCastException at runtime.