Why the main() method in Java is always static?

0 votes
public static void main(String args[])

Can someone explain why this method is always static? I mean if there is some specific reason, please do explain.

May 8, 2018 in Java by misc.edu04
• 1,420 points
415 views

1 answer to this question.

0 votes

As you might know, static here is an access modifier, which is used for the memory management. It can be used with various variables, methods, blocks and nested classes.

When a method is declared as static:

  1. It belongs to the class and not to the object of the class

  2. It can be then invoked, without the using the object of the class

  3. Also, it can access the static members of a class and edit them.

By using the static keyword with a method, basically helps in removing the ambiguity in case there is some other main method in your program.

answered May 8, 2018 by geek.erkami
• 2,640 points

Related Questions In Java

0 votes
2 answers

Why it is not possible to define a static method in a Java interface?

Interfaces are concerned with polymorphism which is ...READ MORE

answered Aug 27 in Java by Sirajul
• 37,080 points
88 views
0 votes
1 answer

What is the concept of Immutability for strings in Java ? Why are strings immutable ?

According to Effective Java, chapter 4, page 73, ...READ MORE

answered May 11, 2018 in Java by Rishabh
• 3,540 points
182 views
0 votes
1 answer

Why there is the need of getters and setters in java

In Java getters and setters are completely ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,280 points
414 views
0 votes
1 answer

What is the difference between main(String[] args) and main(String... args) in Java?

String[] is used to accept a single parameter ...READ MORE

answered Sep 6 in Java by Piya
52 views
0 votes
1 answer

Overriding private or static method in Java

You cannot override a private or static ...READ MORE

answered Jul 30, 2018 in Java by code.reaper12
• 3,450 points
98 views
0 votes
2 answers

“Could not find or load main class” mean?

Use the final modifier to enforce good initialization. Avoid returning ...READ MORE

answered Sep 18, 2018 in Java by Sushmita
• 6,880 points
1,806 views
0 votes
2 answers

What is the use of toString method in Java and how can I use it ?

Whenever you require to explore the constructor ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,050 points
804 views
0 votes
2 answers

How do I replace character from string at specific indexes?

You could turn the String into a ...READ MORE

answered Aug 22 in Java by Sirajul
• 37,080 points
48 views
0 votes
1 answer

Why clone() method is protected in Java?

The clone() is protected because it is ...READ MORE

answered Nov 12, 2018 in Java by geek.erkami
• 2,640 points
548 views
0 votes
2 answers

Listing all the subclasses of a specific class in Java

This is not possible to do using ...READ MORE

answered Aug 21 in Java by Sirajul
• 37,080 points
340 views