InterviewSolution
Saved Bookmarks
| 1. |
What does “static” mean in public static void main(String args[])? |
|
Answer» The public static void main(String args[]) is the main METHOD of the Java Program. It is the most important Java Method. It is the entry point of any Java Program. A Java Program cannot be executed without the main method. The static KEYWORD acts as an access modifier. When the Java Virtual Machine calls out to the main method, it has no object to call to. Hence, we use static to permit its call from the class. If we do not use static in public static void main(String args[]), then the compiler will GIVE an error message. public class Example { public void main(String args[]) { System.out.println("Hello"); } }The output window is as FOLLOWS $javac Example.java $java Example Error: Main method is not static in class Example, please define the main method as: public static void main(String[] args) |
|