Multiple choice technology programming languages

Program output : package com.collection.examples; import java.util.HashSet; public class HashSetExample { public static void main(String[] args) { HashSet s = new HashSet();//1 for(short i = 0; i<100;i++){ //2 s.add(i); //3 s.remove(i-1); //4 } System.out.println(s.size()); //5 } }

  1. NumberFormat Exception

  2. 100

  3. Compilation fails at line 4

  4. 99

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

The loop variable is of type short, but the expression i minus one is promoted to an int. Consequently, remove is invoked with an Integer object, which never matches any Short objects in the set, leaving the set size at one hundred.