Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2004
    Posts
    9

    Unanswered: constructor returning

    Hello people
    I heard that constructor doesnot return anything.But I tried the following code.
    I cant understand the real thing about constructor.Help me.
    /*
    This code compiles without any problems
    */

    class sample {

    public int sample()
    {

    return 5;
    }


    public static void main(String a[])
    {

    }

    }

  2. #2
    Join Date
    Jul 2003
    Posts
    73
    Constructors do not return anything (essentially, they return void).

    There is no reason you should be issuing a return statement in a Constructor. Are you trying to give a return code from your java application?

    You may be trying to do this:

    Code:
    System.exit(5);
    Joel Dixon
    Analyst Programmer
    Melbourne, Australia

Posting Permissions

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