just want to ask if the class i created below is correct or if something is wrong because of the use of static list of objects and if my implementation of encapsulation in correct because i need to limit the access to my static variable.
public class Car {
private String carName, carPlateNumber;
private static List<Car> carList;
public Car(String carName, String carPlateNumber) {
super();
this.carName = carName;
this.carPlateNumber = carPlateNumber;
}
public String getCarName() {
return carName;
}
public void setCarName(String carName) {
this.carName = carName;
}
public String getCarPlateNumber() {
return carPlateNumber;
}
public void setCarPlateNumber(String carPlateNumber) {
this.carPlateNumber = carPlateNumber;
}
public static void createCarList() {
carList = new ArrayList<Car>();
}
public static void addCarToList(Car car) {
carList.add(car);
}
public static Car getCarAt(int location) {
return carList.get(location);
}
public static void clearCarList() {
carList.clear();
}
public static List<Car> getCarList() {
return carList;
}
}
and then to use this class like this
Car.createCarList();
Car.addCarToList(new Car("Mustang","CA-12343"));
. . .
. . .
and so on....
Car? Feels weird that the bean you're using has a cache of itself and its other instances.enuminstead?enuminstead?" How and why would you use anenum?