title: Creating different objects from one method
body: <p>Is there any way to generate different types of objects from one method without using long and complicated if-statements?</p>
  
  <p>Lets say I've created an abstract class called Vehicle. Vehicle has a constructor like this:</p>
  
  <pre><code>public abstract class Vehicle {
    int mileage;
  
    public Vehicle (int mileage) {
      this.mileage = mileage;
    }
  }
  </code></pre>
  
  <p>Now, I've created lots and lots of different types of vehicles that all inherits Vehicle, such as DuneBuggy, SmallCar, MediumCar, BigCar, FastCar, OldCar, NewCar, PickUpTruck, SmallTruck, MediumTruck, LargeTruck, Bicycle, Tram, Train and so forth and so on. To my understanding they're now all Vehicles since they inherit Vehicle.</p>
  
  <p>Is there any way I can get vehicle type from user together with mileage and create the correct type of vehicle by passing it to one method no matter what type of vehicle the user has selected? Something like this:</p>
  
  <pre><code>public void createNewVehicle (Variable someKindOfWayToPickVehicleType, int mileage) {
    // Create a new vehicle where exact class is decided by someKindOfWayToPickVehicleType variable
  }
  </code></pre>