Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7742633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:19:29+00:00 2026-06-01T09:19:29+00:00

I was recently asked in an exam if public static void main(String arg[]) format

  • 0

I was recently asked in an exam if public static void main(String arg[]) format of main method was fixed?
Can we change it?
Can we use main without any of public, static or void?
If not, why is it not hard coded that main(String arg[]) would stand for public static void main(String arg[]) always?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:19:30+00:00Added an answer on June 1, 2026 at 9:19 am

    The signature of the main method is specified in the Java Language Specifications section 12.1.4 and clearly states:

    The method main must be declared public, static, and void. It must
    specify a formal parameter (§8.4.1) whose declared type is array of
    String.

    • it must be public otherwise it would not be possible to call it
    • it must be static since you have no way to instantiate an object before calling it
    • the list of String arguments is there to allow to pass parameters when executing a Java program from the command line. It would have been possible to define it without arguments but is more practical like that (and similar to other languages)
    • the return type is void since it does not make sense to have anything else: a Java program can terminate before reaching the end of the main method (e.g., by calling System.exit())

    The method signature can therefore be:

    public static void main( String[] args )
    public static void main( String... args )
    

    note that the varargs version (...) is only valid from Java 5

    As the Java language allows the brackets [] to be positioned after the type or the variable (the first is generally preferred),

    public static void main( String args[] ) // valid but usually non recommended
    

    is also valid

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently asked another question pertaining to avoid having to use boilerplate exceptions when
I recently asked a question here, and someone provided this answer: private void button1_Click(object
I recently asked/accepted an answer to a question I had earlier: How can I
I've recently asked a question on StackoverFlow about the MVC: Can the MVC Design
I recently asked a question about what I called method calls. The answer referred
I recently asked this question: Compiler error referencing custom C# extension method Marc Gravell
I recently asked about composite keys in maps in clojure : How can you
I was recently asked to create a web page using a static website generator,
I recently asked a question about formatting JavaScript code in Vim. And I've also
I recently asked the question Is the behavior of return x++; defined? The result

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.