Interview Q&A / Java

BeginnerQuick answer1 min readUpdated 3 Oct 2026

Why is the main method public static void in Java?

SHORT ANSWER

public so the JVM can call it from outside, static so it can run without creating an object, void because the JVM does not use a return value, and String[] args carries the command-line arguments.

Explain it simply

Starting a bus needs a key that the driver can reach (public) and does not need a passenger on board (static). The depot does not expect anything handed back when the bus leaves (void).

Example

java
public class Hello {
    public static void main(String[] args) {
        System.out.println("Args: " + args.length);
    }
}
// java Hello one two   prints: Args: 2

// All of these are fine as overloads, but the JVM calls only the String[] one:
// public static void main(int x) { }

What to say in the interview

"The JVM looks for exactly this signature to start the program. public means it is accessible from outside the class, static lets the JVM call it on the class before any object exists, and void is because the exit code is set through System.exit and not through a return value. String[] args holds the command-line arguments. If I leave out static, the program compiles but fails at launch with an error saying main must be static. Newer Java versions have preview features that relax this for small programs, but the classic form is the standard."

Common mistakes

  • Thinking the name main is a keyword. It is a convention that the launcher looks for.
  • Writing String args without the brackets.

#java#keywords#basics

Related questions

Practise more Java questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Java quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.