Computer Applications
The main function in a Java program is declared as:
public static void main (String args[])
What is the significance of the words public, static and void?
Java Intro
ICSE 2007
173 Likes
Answer
public — The public keyword is an access specifier. It controls the visibility of class members. We can access public class members outside the class where we declare them. We need to make the main method public because it will be called by code outside of its class when the program is started.
static — When we declare a method inside a class as static, we can call it without creating the object of that class. We need to make the main method static because Java Virtual Machine (JVM) will call it to start the program even before any objects of the class are created.
void — The void keyword tells the compiler that the main method will not return any value.
Answered By
111 Likes