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 an entry for a key k such that Objects.equals(key, k).
import java.util.*;interface Vehicle { void start();}class Car implements Vehicle { public void start() { System.out.println("Starting a Car"); }}class Motorcycle implements Vehicle { public void start() { System.out.println("Starting a Motorcycle"); }}class Garage<T extends Vehicle> { private Map<String, T> vehicles; public Garage() { vehicles = new LinkedHashMap<String, T>();//LINE A }
public void add(String name, T vehicle) { vehicles.put(name, vehicle); } public void startVehicle(String name) { if (vehicles.containsKey(name)) { T v = vehicles.get(name); //LINE B v.start(); } else { System.out.println("Vehicle not found"); } }}public class TestGarage { public static void main(String[] args) { Garage<Vehicle> g = new Garage<Vehicle>(); Vehicle v1 = new Car(); Vehicle v2 = new Motorcycle(); g.add("car", v1); g.add("motorcycle", v2); g.startVehicle("car"); g.startVehicle("bicycle"); }}Choose the correct option.
