CollegeTester.java:10: error: non-static method getCommand() cannot be referenced from a static context
getCommand();//goes to command
^
如何输入此方法。使其public static void
不仅会导致更多的问题如何从静态方法输入非静态方法
main()
称这个为
main()
import java.util.Scanner;
public class CollegeTester
{
public String name;
Scanner input = new Scanner(System.in);
public static void main(String[] args)
{
getCommand();//goes to command
}
//Ask user for a command
public void getCommand()
{
// do stuff
}
}
你真的应该问这个任何更多的问题之前(静态和实例方法之间的区别就在这里特别)了解更多一点关于OOP现场。 – Njol
除了恩乔尔的建议之外,我还应该将CollegeTester课程与主课程分开。 – KarelG
[非静态方法(方法名称()))的重复可能不能从静态上下文中引用。为什么?](http://stackoverflow.com/questions/11282093/non-static-method-method-name-cannot-be-referenced-from-a-static-context-wh) – 2014-01-29 08:48:32