Created
March 23, 2021 11:49
-
-
Save LokeshAggarwal2/bb50de544e1817b8748fbec676347ec9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CarFactory { | |
public Car getCar(String carType){ | |
if(carType == null) { | |
return null; | |
} | |
if(carType.equalsIgnoreCase("Hyundai")) { | |
return new Hyundai(); | |
} | |
else if(carType.equalsIgnoreCase("Maruti")) { | |
return new Maruti(); | |
} | |
else if(carType.equalsIgnoreCase("Tata")) { | |
return new Tata(); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment