I have 3 objects
Car
SmallCar extends Car
LargeCar extends Car
Using this method i want to count cars of specific type in a list:
public int availableCars(String carType) {
int count = 0;
for (Car i : fleet) {
if (i instanceof SmallCar) {
count++;
}
}
return count;
}
What is the best way to pass the carType given (if it is as String or something else that would be better) to have something like:
if (i instanceof carTypeGiven)
The method returns how many cars of specific type are available.