Answers for "codegrepper java instanceof"

0

codegrepper java instanceof

if (vehicle instanceof Car) {
        Car car = (Car) vehicle;
        return car.wheelCount;
     } else if (vehicle instanceof Bike) {
          Bike bike = (Bike) vehicle;
         return bike.numberOfWheels;
     } else {
         throw new IllegalArgumentException("Unrecognized vehicle");
     }
Posted by: Guest on October-26-2021
0

codegrepper java instanceof

if (vehicle instanceof Car car) {
        return car.wheelCount;
     } else if (vehicle instanceof Bike bike) {
         return bike.numberOfWheels;
     } else {
         throw new IllegalArgumentException("Unrecognized vehicle");
     }
Posted by: Guest on October-26-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language