aspose file tools*
The moose likes Beginning Java and the fly likes Regrding Access Specifier used of main method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regrding Access Specifier used of main method" Watch "Regrding Access Specifier used of main method" New topic
Author

Regrding Access Specifier used of main method

AjayP Singh
Greenhorn

Joined: Jan 25, 2006
Posts: 1
I want to know what is the significance of public access modifier with main (String args[]) method. Like generally we write
public static void main(String args[])
{
}

But if we write
private static void main(String args[])
{
}
OR
protected static void main(String args[])
{
}

then also its working properly.............
then what is the use of public keyword..........................

Regards

Ajay Pratap Singh
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
It works properly when compiling.

But have you tried running the program that doesn't have the keyword public in the header of the main method?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

As of Java 1.4, main methods are required to be public in order to be program entry points (i.e., run from a command prompt).

A non-public method called "main" is perfectly valid -- it just can't be used as a program entry point.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regrding Access Specifier used of main method
 
Similar Threads
Help Me...Doubt in Overloading..
Static Variable Problem
can somebody explain this?
What is the main usage of "String[] args" in public static void main(String[] args)?
Why we pass string object to main?