Skip to content

Instantly share code, notes, and snippets.

@LokeshAggarwal2
Created March 23, 2021 11:49
Show Gist options
  • Save LokeshAggarwal2/bb50de544e1817b8748fbec676347ec9 to your computer and use it in GitHub Desktop.
Save LokeshAggarwal2/bb50de544e1817b8748fbec676347ec9 to your computer and use it in GitHub Desktop.
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