Basically I want the program to take input A or L to instantiate different classes. I have the construct in place for taking in those variables and such, I just need to know how to actually create a condition or switch that will initialize a class given the input. Code is as follows:
public constructor(char choice){
if(choice == 'A'){
classa<String> baga = new classa<String>();
classa<String> bagb= new classa<String>();
}
else if(choice== 'L'){
classb<String> baga = new classb<String>();
classb<String> bagb = new classb<String>();
}
}
If you want these variables to have different types, and you still expect to get some use out of them, then they must have some common operations. Those operations can be factored into a
Baginterface:Incidentally, a
charis not really type-safe here; I would use an enumeration. Further, I don’t like the use of mutation, so perhaps I’d go for something more along these lines: