So, I have two classes. One abstract:
public abstract class AbstractClient {
protected boolean running = true;
protected void run() {
Scanner scanner = new Scanner(System.in);
displayOptions();
while (running) {
String input = null;
while (scanner.hasNext()) {
input = scanner.next();
}
processInputCommand(input);
}
}
abstract void displayOptions();
abstract void processInputCommand(String input);
}
One of them is a specific subclass:
public class BasicClient extends AbstractClient {
private IBasicServer basicServer;
public static void main(String[] args) {
new BasicClient();
}
public BasicClient() {
try {
System.setSecurityManager(new RMISecurityManager());
Registry registry = LocateRegistry.getRegistry();
basicServer = (IBasicServer) registry.lookup(IBasicServer.LOOKUPNAME);
run();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
void displayOptions() {
BasicClientOptions.displayOptions();
}
@Override
void processInputCommand(String input) {
}
}
Now in the subclass, I call the run () method of the abstract class, because this should be common to all clients. Inside the run () method, there is a call to the abstract displayOptions () method.
I have an overridden displayOptions () in a subclass, so I assumed that it would call the subclass method, but it didn't seem to do that. Is there a way to do this, or did I make a clear mistake or did I misunderstand how abstract classes should work?
PS I tried putting the print statement inside a subclass of displayOptions () to make sure I didn't do anything stupid with the method I call.
Many thanks,
Adam