2 Replies Latest reply on Nov 18, 2006 5:06 PM by 807599


      this is part of my x-tra credit lab-

      The smiley face will have at least the following methods:
      Constructor, change position, change color, happyOrSad (changes its mouth and winks for happy, has a tear for sad), change size.

      Can I create the happy face in it's own method and call other methods? And also, what's a constructor?
        • 1. Re: constructors
          class TestClass {
               public TestClass() { ... } /** this is a constructor. */
          • 2. Re: constructors
            And also, what's a constructor?
            I'm not sure what the other part of your question is asking, but a constructor is the method that is called when an object of a class is created. The constructor has the same name as the class, and has no return value. For example:
            class Test
                 public int i;
                 public Test(int initi)
                      this.i = initi;
            This defines a class with the field i, and a constructor that sets the inital value of i. When you create the object:
            Test obj = new Test(3);
            This code will print the number 3 on the screen, since that is the value you set i to when you passed a parameter to the constructor. Constructors don't have to take parameters, nor do you even have to define one in your class.