Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
import java.util.HashMap;
import java.util.Map;
class Vehicle {
}
class Motorcycle extends Vehicle {
}
class Bus extends Vehicle {
}
class Car extends Vehicle {
}
public class Demo {
public static void main(String... args) {
Map<String, Vehicle>map = new HashMap<String, Vehicle>();
map.put("motorcycle", new Motorcycle());
map.put("bus", new Bus());
map.put("car", new Car());
System.out.println(map);
}
}