This is bad programming practice but I’ve been asked to do it as part of a larger assignment.
I am creating a superclass and then 2 subclasses. There is a static method in the superclass that should return either of the 2 subclasses depending on the result. How would I go about writing this method?
For example I need to do something like this
public abstract class Superclass{
public static subclass? createFromFilename(String fileName){
if(1==1)
return subclass1;
else
return subclass2;
}
}
Is this even possible?
You can do it like this
You can now do this