我正在尝试在我的其他课程中调用statemotOfPhilosopy
。
有两个类:
头等课SetUpSite
:
package setupsite;
public class SetUpSite {
public static void main(String[] args) {
statementOfPhilosophy();
}
public static void statementOfPhilosophy() {
System.out.println("Even Handlers Incoroporated is");
System.out.println("dedicated to making your event");
System.out.println("a most memorable one.");
}
}
第二课CallingMethods
:
package callingmethods;
public class CallingMethods {
public static void main(String[] args) {
System.out.println("Calling method from another class:");
SetUpSite.statementOfPhilosophy(); //Error here at the SetUpSite
}
}
答案 0 :(得分:1)
您忘记添加导入语句添加此行 :: import setupsite.SetUpSite
package setupsite;
public class SetUpSite {
public static void main(String[] args) {
statementOfPhilosophy();
}
public static void statementOfPhilosophy()
{
System.out.println("Even Handlers Incoroporated is");
System.out.println("dedicated to making your event");
System.out.println("a most memorable one.");
}
}
package callingmethods;
import setupsite.SetUpSite
public class CallingMethods {
public static void main(String[] args) {
System.out.println("Calling method from another class:");
SetUpSite.statementOfPhilosophy();
}
}
答案 1 :(得分:0)
您必须导入setupsite
包。
您的代码将如下所示:
package callingmethods;
import setupsite.SetUpSite;
public class CallingMethods {
public static void main(String[] args) {
System.out.println("Calling method from another class:");
SetUpSite.statementOfPhilosophy(); //Error here at the SetUpSite
}
}
答案 2 :(得分:0)
你必须在import setupsite
打包:
import setupsite;
然后试试。