problem with main() method


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: problem with main() method

  1. #1
    Vikas Babbar Guest

    problem with main() method


    The problem is related with the decleration of the main method.
    The JVM should match the signature of the main method as
    public static void main( String[] args ). It is mentioned everywhere that
    if this signature does not match, the program will not complie. Still, the
    following code works perfectly:

    -----------------------------------------------------------------
    class Strange
    {
    private static void main(String[] args)
    {
    System.out.println("Hello Strange!");
    }
    }

    class Ex extends Strange
    {
    private static void main(String[] args)
    {

    Strange.main( args ) ;
    System.out.println("Hello Ex!");
    }

    }

    ----------------------------------------------------------------

    Even if I use a single class and declare a main method as private, the code
    complies and runs fine.

    Please post your reply at my mail address: vbbr@usa.net.

    Thanx.

    Vikas

  2. #2
    Ashish patel Guest

    Re: problem with main() method


    It doesn't work. Since , the Ex class tries to call a private method main
    of the class strange !
    But any way , its not rule that the main mathod has to be public.
    But the rule is ,
    (1)main has to be static
    (2)string array argument has to be there.
    (3)the class that contains main has to be the same name as
    the source file. if it is not so, it will compile but will not
    run.


    "Vikas Babbar" <vbbr@usa.net> wrote:
    >
    >The problem is related with the decleration of the main method.
    >The JVM should match the signature of the main method as
    >public static void main( String[] args ). It is mentioned everywhere that
    >if this signature does not match, the program will not complie. Still, the
    >following code works perfectly:
    >
    >-----------------------------------------------------------------
    >class Strange
    >{
    > private static void main(String[] args)
    > {
    > System.out.println("Hello Strange!");
    > }
    >}
    >
    >class Ex extends Strange
    >{
    > private static void main(String[] args)
    > {
    >
    > Strange.main( args ) ;
    > System.out.println("Hello Ex!");
    > }
    >
    >}
    >
    >----------------------------------------------------------------
    >
    >Even if I use a single class and declare a main method as private, the code
    >complies and runs fine.
    >
    >Please post your reply at my mail address: vbbr@usa.net.
    >
    >Thanx.
    >
    >Vikas



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