public void setupPlayers() {
System.out.println("Would you like the Code Maker to be Human or CPU? :");
String input = mySc.next();
if (input == "Human") {
Player CodeMaker = new Human();
}
else {
Player CodeMaker = new CPU();
}
public void exampleUse() {
CodeMaker.getCode();
}
So I'm new to Java and not even sure if this is possible to begin with. The above code is all inside one class. Human is implementing the interface Player. I want to create an object CodeMaker using the class Human in the method setupPlayers, and then use this object in the method exampleUse. Is there a way to do this? If not can anyone think of any alternatives? Cheers.