Suppose I have the following classes:
class car1 {}
class car2 {}
class car3 {}
class car4 {}
Support I also have the method: queryCar()
private Object queryCar()
{
int version = getCarVersion(); // returns car version
if (version == 1)
return new car1();
else if (version == 2)
return new car2();
else if (version == 3)
return new car3();
...
}
I have another method, doStuff()
private void doStuff()
{
// psudocode
if queryCar() returns a car1, I want to create a JPanel with an instance member of type car1
}
How do I accomplish said psudocode? InstanceOf works for determining the class. However, I only want one class to autogenerate that car on runttime. (Thinking of an analog of C++ pointers in java)
instanceof