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 ?
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 ?
- Since main method is static JVM can call the method without creating any instance of the class in which the method belongs.
- Like other C and C++ main is the entry point.
- If the main method is not static JVM has to create instance for the class to access the method.
- Since method is public it can be accessed outside the class.
- since main method doesn't return any value it's made void.
No comments:
Post a Comment