我怎樣才能調用非靜態方法主要class.I我得到如下因素的錯誤在我的示例控制檯應用程序異常在線程「主」了java.lang.RuntimeException:不可編譯源代碼
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static method doSomthing() cannot be referenced from a static context
at sample.Main.main(Main.java:20)
和代碼是,
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
doSomthing();
System.out.print("From Main");
}
protected void doSomthing()
{
System.out.print("From Main doSomthing");
}
}
爲什麼要從靜態方法調用非靜態方法? – MrSmith42