1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

why a class contains main method has to made public

Discussion in 'Java' started by sakthi.abdullah, Jun 20, 2007.

  1. sakthi.abdullah

    sakthi.abdullah New Member

    Joined:
    Mar 15, 2007
    Messages:
    29
    Likes Received:
    1
    Trophy Points:
    0
    Hi
    Why a class containing main method has to made public..?
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    public indicates that the main method can be called by any object.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    I am not a Java expert that reason could be for having the main public but for having the class public the reason could be it can be invoked from any package.
     

Share This Page