Enter your E-mail Address below for Free E-mail Alerts right Into your Inbox: -

Wednesday

Why main method in java is public static

Why main method in java is public static

Every java developer knows that public static void main(String args[]) is the entrance point for a java program.Did you ever thought why its public static ?


  1. Since main method is static JVM can call the method without creating any instance of the class in which the method belongs.
  2. Like other C and C++ main is the entry point.
  3. If the main method is not static JVM has to create instance for the class to access the method.
  4. Since method is public it can be accessed outside the class.
  5. since main method doesn't return any value it's made void.

No comments:

Post a Comment