Results 1 to 9 of 9

Thread: Declare main method as private

  1. #1

    Declare main method as private

    If we declare the main method as private instead of public it will execute or not


  2. #2
    Contributing Member
    Join Date
    Sep 2006
    Answers
    962

    Re: hi

    No error on complile time. But you got the run time error like "main method is not public".

    --------------------
    suresh


  3. #3
    Junior Member
    Join Date
    May 2006
    Answers
    4

    Re: hi

    No...because,execution will start from main itself....it needs to accessable by anywhere....


  4. #4
    Contributing Member
    Join Date
    Sep 2006
    Answers
    962

    Re: Declare main method as private

    hi ramesh,

    Are you trying for this one? Don't you get error at run time?

    -------------------
    suresh


  5. #5
    Junior Member
    Join Date
    Sep 2007
    Answers
    3

    Smile Re: Declare main method as private

    No U cant declare main method as Private.
    During runtime it gives no such method error.


  6. #6

    Re: Declare main method as private

    hi ,

    In run time,jvm checks main method with this convention(public static void main(String args[]) )
    if you dont define this method as actually defined, JVM shows run time error as no such method.it wont execute any statement of any other main method.


  7. #7
    Junior Member
    Join Date
    Sep 2007
    Answers
    5

    Re: Declare main method as private

    Quote Originally Posted by rajesh.tripathi View Post
    If we declare the main method as private instead of public it will execute or not
    NO it will not execute, normally main method is executed by JRE Interpretor
    Making it private would not provide access to JRE.

    vj


  8. #8
    Junior Member
    Join Date
    Aug 2007
    Answers
    3

    Re: Declare main method as private

    Dear Rajesh,

    The Main Method will not execute if you will declare as private . It should be public .

    Regards,
    Jayant





    Quote Originally Posted by rajesh.tripathi View Post
    If we declare the main method as private instead of public it will execute or not



  9. #9
    Junior Member
    Join Date
    Feb 2007
    Answers
    1

    Re: Declare main method as private

    One can declare the main method as private, but a main method with private access specifier will not be treated by the java runtime, as entry point of the program.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact