1

In c++ we write main function at last and in c if there are any forward function calls we will declare functions in the beginning or we will define all the functions first then we will write main function. But in java even if we write main method in the beginning then other methods and if we call other methods from main method..it wll execute..why? How will it come to know there is some method defined in the program?

class Temp{

    public static void main(String args[]){

      display();

    }

    public static void display(){

       System.out.println("HI");

    }
}
Jeet
  • 5,569
  • 8
  • 43
  • 75
RakshaGShenoy
  • 153
  • 1
  • 1
  • 6
  • I think you should google for "java compile, class load, jvm function" or somthing like that, and ask about what you could not understand. The question you ask seems some broad and could not get a good answer for you at this step. – Al2O3 Jul 05 '16 at 05:03

2 Answers2

6

Unlike C++, we don’t need forward declarations in Java. Identifiers (class and method names) are recognized automatically from source files

http://www.geeksforgeeks.org/do-we-need-forward-declarations-in-java/

hellrocker
  • 628
  • 8
  • 15
-1

I guess that the compiler loads all classes before executing the program.