Results 1 to 4 of 4

Thread: How come 'private static void main()' works?!

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    32

    How come 'private static void main()' works?!

    Since, I have some basic exposure to Java, I find this rather curious! Unless main method is 'public' how is the class instantiated?? Anybody answers?

    Sujala

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    As far as I understand it because it's static the class
    does not have to be instantiated to use Main or ant other
    static methods

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    32

    No no

    No no, the class is not instatntiated to access the main method. Its the other way round, the main method is used to instantiate the class. Since the main method is 'static' it can be accessed from the class only, i.e. an instance of the class is not required to access it. But my qs. is if the method is 'private' how can it be called from outside the class?

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    When the application is executed, the CLR searches the module(s) for the application entry point, whether or not the Main() method is private or public does not matter (I read this in a book, so you may want to test..).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width