wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Accessibility of main() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Accessibility of main()" Watch "Accessibility of main()" New topic
Author

Accessibility of main()

Greg Torrance
Greenhorn

Joined: Feb 25, 2000
Posts: 17
Hi there,
I am new to the forum - (great group BTW!) - and was wondering if someone can clear something up for me. I keep reading that the main() method must be defined as public and static, but when I run a test with a private or protected main() method, it works. Why is this?
For example, if I create class Test1 as follows:
class Test1
{
private static void main( String[] args )
{
System.out.println( "private main" );
}
}
And then I run it as
java Test1
I get the "private main" message.
Any thoughts?
Thanks,
Greg
Thandapani Saravanan
Ranch Hand

Joined: Oct 17, 1999
Posts: 117
Actually this has already been discussed a couple of times. As per JLS the method must have the following signature:
public static void main(String args[])
If the compiler allows other versions, then we could say it is a bug in compiler. At the same time, we don't get anything more by changing the specification, do we?

Saravanan
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Thandapani,

Is that really a bug or there is something we are really missing...

faisal usmani
Ranch Hand

Joined: Jan 14, 2006
Posts: 139
yep !! it was a bug, in older java versions that is prior to java 1.4 , we can make main method as default or private.


Though it has been rectified now.


-faisal
 
wood burning stoves
 
subject: Accessibility of main()
 
Similar Threads
Static keyword Doubt
Accessibility of main()
what happen if all constructor of a class be declared as private?
instanceof question?
I know high level classes can not be declared private but...