Main method


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Main method

  1. #1
    kal Guest

    Main method


    Is it correct way of defining the main method as

    static void main( String args[]) with out public . what are the implications
    of this because when i compile using this it is comping fine and there are
    no run time errors too. Can any one help me.

    thanks
    kal

  2. #2
    Paul Clapham Guest

    Re: Main method

    You can compile and run? Then there's no problem, right?

    kal <k_paladugu@hotmail.com> wrote in message
    news:392aac18$1@news.devx.com...
    >
    > Is it correct way of defining the main method as
    >
    > static void main( String args[]) with out public . what are the

    implications
    > of this because when i compile using this it is comping fine and there are
    > no run time errors too. Can any one help me.
    >
    > thanks
    > kal




  3. #3
    Karnos Guest

    Re: Main method


    When you don't explicitly declare something as public, it's declared by default
    as package accessible. This means that only objects from classes within
    the same package as the method/attribute can see it. With a main() method,
    this isn't usually a problem, as calling main() methods from existing objects
    is a rarity. But you should always type "public" if that's what you want.
    There's no reason not to, unless those extra six key strokes will cause
    your CTS to manifest.

    "kal" <k_paladugu@hotmail.com> wrote:
    >
    >Is it correct way of defining the main method as
    >
    >static void main( String args[]) with out public . what are the implications
    >of this because when i compile using this it is comping fine and there are
    >no run time errors too. Can any one help me.
    >
    >thanks
    >kal



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center