So, in short. I have two classes.
package rpg;
public class Engine {
public void main(String args[]) {
Start.gameStart();
System.out.println(menuResult);
}
}
and
package rpg;
public class Start {
int menuResult = 3;
public int gameStart()
{
return menuResult;
}
public int getMenuResult()
{
return Start.menuResult;
}
}
It keeps throwing up the error 'Cannot make static reference to non-static method gameStart()'. I'm sure I'm missing something simple, but can't find it. Thanks!
You need to create instance of
Start
class and callgameStart()
method on that instance becausegameStart()
is instance method not static method.Only static methods can be accessed by using class name as perfix.