假设方法 M1 在 program.Does 中调用方法 M2,方法定义的顺序有什么不同?

Suppose method M1 calls method M2 within a program.Does the order of method definition make any difference?

请向我解释 basics.I 我是 Java 编程的初学者

与 Java 中的其他语言不同,您定义方法的顺序无关紧要。

即使M2的定义晚于M1,M1也可以调用M2。

简答,没有。方法声明的顺序无关紧要。这是一个工作示例:

class Foo{

    public static void main(String[] args){
       Bar myInstance = new Bar();
       myInstance.M1(); 

    }
 }

class Bar{

   public M1() {
   // do something
    System.out.println(“Hey! Someone called me! I’m here!”)
    M2();
   }

    public M2() {
    System.out.println(“Hey! Someone called me! I’m here!”)
}