0
HashMap myMap = new HashMap<Character, Character>();

Map myMap = new HashMap<Character, Character>();

What is a more technical way to describe the difference between the two above lines of code, in terms of object oriented programming and polymorphism during an interview?

A non technical way seems like it would be:

The left side of the equals sign is how we "talk" to the object, the right said is what the object actually is. The left side could be an interface, but the right has to be an instantiable class since we can't instantiate an interface.

PM 77-1
  • 12,933
  • 21
  • 68
  • 111

1 Answers1

0

A more technical way to describe them is that in the first line you're declaring a variable named myMap of type HashMap and instantiating it as an object of same type HashMap. In the second line, you're declaring a variable named myMap of type Map and instantiating it as an object of type HashMap which is possible by leveraging polymorphism due to the hierarchical class relationship between object types Map and HashMap.

Javier Silva Ortíz
  • 2,864
  • 1
  • 12
  • 21