Reputation: 95
I compiled the following code through notepad
class MainClass{
public void main(String args[]){
System.out.println("Hello!");
}
}
I didn't use static keyword and the above code executed, but when I did
javap MainClass
in the command prompt,I got the following output,
class MainClass {
MainClass();
public static void main(java.lang.String[]);
}
the keyword was added itself, so is
public void main(String args[])
also considered a valid signature?
Upvotes: 2
Views: 1230
Reputation: 140318
As stated in JLS Sec 12.1.4:
The method main must be declared
public
,static
, andvoid
. It must specify a formal parameter (§8.4.1) whose declared type is array ofString
.
I think you might have been looking at an out-of-date version of the class; when I tried decompiling your code, static
has not been added.
Compiled from "MainClass.java"
class MainClass {
MainClass();
public void main(java.lang.String[]);
}
Upvotes: 5