File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access modifier for main method

 
sangeetha hariharan
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have one doubt.Is it true that the main method can be marked with an access modifier other than "public"?.can we mark it with some other access modifier?I got this doubt because it is mentioned in the book "scjp exam study guide by katthy sierra and Bert Bates" that 'for the purpose of the exam assume that the main method should be marked public'.
could anyone please explain it???
 
Carl Trusiak
Sheriff
Posts: 3340
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, Yes the main method you use to start an application must be public! Now having said that, there is a bug with some releases of the JDK which will allow an app to start even if the main method is declared private. Also, this is only if you wish to start the app with that, nothing prevents you from declaring the main method with another access modifier and calling it from an already running app under the constraints of the access modifier chosen. The main method is just another method. To use it to start an application the signiture MUST be:
public static void main(String[] carl)
 
Jeff Langr
author
Ranch Hand
Posts: 799
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Carl Trusiak:
To use it to start an application the signiture MUST be:
public static void main(String[] carl)


Drat, no wonder I was having problems, I was using:

all along.

-J-
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic