Linked Questions
55 questions linked to/from Why is the Java main method static?
17 votes
9 answers
11k views
why main method can't be of default scope? [duplicate]
If we declare the class with default scope(non-public) and public main method it executes successfully. Here class scope is mote stricter than main method scope. But if we declare main method as ...
13 votes
9 answers
6k views
Why main method is static in java [duplicate]
I have heard some people saying " if main is not static then JVM could create an object of class containing main and call that main through object. But the problem is how JVM knows which constructor ...
6 votes
1 answer
37k views
Why main() is declared public and static in java [duplicate]
Why is the main declared as public and static? public static void main(String arg[]) {} acording to ans in java "The method is static because otherwise there would be ambiguity: which constructor ...
-1 votes
5 answers
1k views
Why main method needs to be static? [duplicate]
Possible Duplicate: Why is the Java main method static? JAVA supports reflection still JAVA needs main method to be static why? Using reflection we can create the object of class and even call ...
2 votes
7 answers
2k views
Why should main be present in a Java class? [duplicate]
Why should we declare a main method? I know that the main method is the starting point of the class. But why should only we declare it as public static void main(String args[])? Why can't we declare ...
0 votes
2 answers
4k views
Is it possible to run java program without static [duplicate]
When we tried to run the following program then it successfully runs. class with { public static void main(String args[]) { System.out.println("With static"); } } but even if we ...
-3 votes
3 answers
3k views
public static void main(String[] args) - why is it actually static? [duplicate]
Possible Duplicate: Why is the Java main method static? What's the reason of main method to be static? Why isn't just public void main(String[] args)? I think I understand what static means, but I ...
0 votes
1 answer
1k views
Why the main method should be in static [duplicate]
The following code gives error because i am not put static keyword to main method. Please explain why main method not working without static keyword. public class Test { public void main(String args[]...
-1 votes
1 answer
1k views
I'm unsure of why, and what the "static" tag does [duplicate]
I'm new to programming in Java (even though I'm used to code in C, html and some other languages (vaguely)). I'm trying to create a simple Hello World program, and I'm unsure of why, and what the "...
-1 votes
1 answer
111 views
Should the main method not be declared static or should the other method be declared static? Java [duplicate]
public class Question { public void doThing() {} public static void main(String[] args) { doThing(); } } Should the doThing() method be declared static to be used in ...
-8 votes
1 answer
120 views
Why is the main method in Java always static? [duplicate]
Onetime I forgot to put the static keyword for the main method in my java class. And the program did not work . So the question is why we always need to mark the main method as static?
0 votes
0 answers
42 views
I am a java beginner. Why the main in java starts with Static keyword [duplicate]
class Student{ public **static** void main (String[]arg){ } } Here why we are using static keyword to start a main method. From my knowledge I can say Static will get memory and it can ...
163 votes
22 answers
500k views
What is the meaning of "this" in Java?
Normally, I use this in constructors only. I understand that it is used to identify the parameter variable (by using this.something), if it have a same name with a global variable. However, I don'...
68 votes
11 answers
233k views
"Error: Main method not found in class MyClass, please define the main method as..."
New Java programmers often encounter messages like the following when they attempt to run a Java program. (Different Java tools, IDEs and so on give a variety of diagnostics for this problem.) Error:...