Multiple choice technology programming languages

What does it print ? import java.util.*; public class NameGame { public static void main(String args[]) { Map m = new IdentityHashMap(); m.put("Mickey", "Mouse"); m.put("Mickey", "Mantle"); System.out.println(m.size()); } }

  1. Exception

  2. Stack Overflow

  3. 2

  4. 1

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

In Java, an IdentityHashMap uses reference equality (==) rather than object equality (equals()) for keys. Since the two string literals "Mickey" are interned, they refer to the exact same string object in memory. Therefore, the second put operation overwrites the first, resulting in a size of 1.