在java中有两种类型的方法:实例方法和类方法。要调用前者,您需要实例化该类,而两个调用后者则不需要。下面是一个例子:public class MyClass{ public String instanceMethod(){ return "This is from instance method"; } public static String classMethod(){ return "This is from class method"; } public static void main(String[] args){ System.out.println(MyClass.classMethod()); //will work System.out.println(MyClass.instanceMethod()); //compilation error MyClass myInstance = new MyClass(); System.out.println(myInstance.instanceMethod()); //will work }}