• anonymous
Why do we put the word static with main method in a Java program?? Can anyone explain with an example please??
Computer Science
  • Stacey Warren - Expert
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
  • jamiebookeater
I got my questions answered at in under 10 minutes. Go to now for free help!
  • anonymous
I'm not sure how to explain with an example since your question is the example lol :P but anyways, the reason why we put static within the main method in Java programs is because the word static just means that there will be only instance of that object in the class. To make it easier to understand, if you didn't have static declared, it would create a new copy of that object every time that class was initialized. This also benefits in time with the program since you can call them directly without having to initialize the class every time. This is why the main method is declared as static so that java doesn't have to initialize it to accomplish the main function. BTW, if you have learned methods, most methods start with static such as: public static int getNum (int n) { code }

Looking for something else?

Not the answer you are looking for? Search for more explanations.