Can we pass the elements of an array as the name of the objects of some Class in Java. Suppose I created a class Cars with some of its attributes.
class Cars {
int maxSpeed;
int mileage;
public double roadTax(int manufactureYear){
int x = 150;
while((manufactureYear<2021) && (manufactureYear > 2010)){
for (int i = 2010; i < manufactureYear; i++)
x += (x + (0.10 *x));
return x;
}
}
We can create some objects for this class with the usual code like
Cars Volvo = new Cars();
Suppose I have a String-Array of brands and I want to create an object for each element in the Array
String[] carBrands= {"Volvo","BMW","Renault","Ford", ..... }
Is there a code we can pass all the elements in the list as the objects of the class Cars, without having to write one for each of them.