Java 如何从一个类调用另一个类中的方法?
我正在尝试调用另一个类中的Java 如何从一个类调用另一个类中的方法?,java,compiler-errors,Java,Compiler Errors,我正在尝试调用另一个类中的statemotOfPhilosopy 有两类: 一等设置站点: package setupsite; public class SetUpSite { public static void main(String[] args) { statementOfPhilosophy(); } public static void statementOfPhilosophy() { System.out.printl
statemotOfPhilosopy
有两类:
一等设置站点
:
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;
public class CallingMethods {
public static void main(String[] args) {
System.out.println("Calling method from another class:");
SetUpSite.statementOfPhilosophy(); //Error here at the SetUpSite
}
}
您必须导入
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
}
}
您必须
在此处导入setupsite
包:
import setupsite;
然后再试。您忘记添加导入语句添加此行:
导入setupsite.setupsite
怎么了?是否导入了
SetUpSite
?是否导入了SetUpSite类: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();
}
}