Question 1
Consider the Java code given below.
The method boolean containsKey(Object key) in the class Map returns true if and only if the map contains a mapping for a key k such that Objects.equals(key, k).
import java.util.*;interface Shape { void draw();}class Circle implements Shape { public void draw() { System.out.println("Drawing a Circle"); }}class Square implements Shape { public void draw() { System.out.println("Drawing a Square"); }}class DrawingBoard<T extends Shape> { private Map<String, T> m = new HashMap<>();// LINE 1 public void add(String name, T shape) { m.put(name, shape); } public void draw(String name) { if (m.containsKey(name)) { T s = m.get(name); //LINE 2 s.draw(); } else { System.out.println("Shape not found"); } }}public class Test { public static void main(String[] args) { DrawingBoard<Shape> dB = new DrawingBoard<Shape>(); Shape s1 = new Circle(); Shape s2 = new Square(); dB.add("circle", s1); dB.add("square", s2); dB.draw("circle"); dB.draw("triangle"); }
}Choose the correct option.