5 Replies Latest reply: Jan 9, 2008 1:35 PM by 807603 RSS

    How do you call the constructor?

    807603
      I must be losing my mind, this seems so simple.

      I've got a class aaa.java with a constructor as follows:

      public void aaa()
      {
      System.out.println("hello");
      }

      And then in my main class I call as follows:

      aaa bbb = new aaa();

      Should this call the constructor of the aaa() class and run the println statement? I must be missing something stupid. It's running through fine, just not hitting the constructor.
        • 1. Re: How do you call the constructor?
          800306
          DeX wrote:
          I must be losing my mind, this seems so simple.

          I've got a class aaa.java with a constructor as follows:

          public void aaa()
          {
          System.out.println("hello");
          }

          And then in my main class I call as follows:

          aaa bbb = new aaa();

          Should this call the constructor of the aaa() class and run the println statement? I must be missing something stupid. It's running through fine, just not hitting the constructor.
          You should always try to use decent class names, even in examples.

          Anyway, the problem is that you don't have a constructor.
          public void aaa()
          isn't a constructor; constructors cannot have a return type.
          • 2. Re: How do you call the constructor?
            807603
            You're right, I knew it was something stupid. Thanks.
            • 3. Re: How do you call the constructor?
              807603
              Djaunl wrote:
              You should always try to use decent class names, even in examples.
              Especially in examples, where you're asking someone you don't know, and who more importantly hasn't got a clue what you're thinking, to make a snap judgement about what you're up to. Vague, abstract names get in the way of us picturing what you're trying to do. GIve me a nice patronising food, animal or transport example any day :-)
              • 4. Re: How do you call the constructor?
                807603
                aaa bbb = new aaa();
                I would respect the Java naming conventions as well. Classnames starts with uppercase. And that would also make more sense in your own code.
                • 5. Re: How do you call the constructor?
                  807603
                  Thanks for the tip, I'll do that.