Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Jidhin Raj   on Sep 05 In Java Category.

  
Question Answered By: Archana Kamble   on Sep 05

The execution of the program begins from the main method. The main method is static so it is invoked by the virtual machine using the class instance internally.
For eg if your class name is "Basic.java" which has public static void main(String args[]) method.
Internally it will call Basic.main();

If it was instance method the VM would have to create Object first then call the main method .This is wastage of memory .Everything main is called it will have to create object then call main method.

main() is public because it is the starting point that is used by the VM to start the execution of the program.

If it is private it won't be visible to the VM.

Share: 

 
 
Didn't find what you were looking for? Find more on Core Java Or get search suggestion and latest updates.


Tagged: