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.
Tutorialspoint

Java Program to create String to super class type mapping

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);
	}
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.