Search code examples
javamethodsstatic-methodsnetbeans-platform

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


Please explain me from basics.I am a beginner in Java programming


Solution

  • Short answer, no. It does not matter order of method declaration. Here is a working example:

    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!”)
    }