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

  • SEARCH
  • Home
  • 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 6682607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:43:34+00:00 2026-05-26T04:43:34+00:00

I do not understand why the main method has to be static. I understand

  • 0

I do not understand why the main method has to be static. I understand static variables but static methods are difficult for me to grasp. Do static method exists so that one can create two methods with the same name in two different classes that won’t clash with each other?

Also, I don’t understand why I can’t create a static constructor.

Could anyone help explain this concept?

  • 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-05-26T04:43:35+00:00Added an answer on May 26, 2026 at 4:43 am

    Java has [static constructors] static initialization blocks which can be viewed as a “static constructor”:

    class Foo {
      static String Bar;
      static {
         // "static constructor"
         Bar = "Hello world!";
      }
    }
    

    In any case, the only method in the main class which must be static is the main method. This is because it is invoked without first creating an instance of the “main class”. A common technique, and the one I prefer, is to quickly get out of static context:

    class Main {
       int argCount;
    
       // constructor
       public Main (String[] args) {
         // and back to boring ol' non-static Java
         argCount = args.length;       
       }
    
       void runIt () {
          System.out.println("arg count: " + argCount);
       }
    
       // must be static -- no Main instance created yet
       public static void main (String[] args) {
          Main me = new Main(args);
          me.runIt();
       }
    }
    

    Also, static has nothing to do with “name clashes”. A static method (or variable) is simply a method (or variable) that is not associated with a specific instance of a type. I would recommend reading through the Classes and Objects Java Tutorial and the section Understanding Instance and Class Variables.

    Happy coding.

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

Sidebar

Related Questions

I am learning Java, theres one thing I do not understand.. in the main
There is one thing that I do not understand... Imagine you have a text
I know the general problem of Can't create handler inside thread that has not
I do not understand pointers. Where can I learn more about them?
I am making a prototype client & server so that I can understand how
I think I understand why this is happening, but I am not sure how
I have encountered a rather odd error that I do not understand. I created
(OBS: English is not my native language and I understand that the title of
I simply do not understand why both works: this.timer.Tick += new EventHandler(timer_Tick); this.timer.Tick +=
I do not understand what environment a eval or exec statement executes in. You

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.