H, beginner here.
I have an abstract class called 'Command', which has several subclasses that extend it, all of which are commands and use the variables and some methods in 'Command'. In a seperate class (that doesn't extend Command), there is some code that invokes these several classes whenever the user does so. The Command class has some variables that I'd like to read from (with getter methods) within the seperate class.
public abstract class Command {
private String variableName;
public String getCurrentVariableName() {
return variableName;
}
}
public class SeperateClass {
// rest of code
System.out.println(command.getCurrentVariableName());
}
Creating an object of the class doesn't work because I can't instantiate an abstract class. I'm guessing I could instantiate one the subclasses and return it using super, but I don't want to unless there is no other way.
Please help
Thanks