title: Set, Get and Constructors in Java
body: <p>Despite Java tutorials, Wikipedia searches, stackoverflow trolling, and hours of reading code samples, constructors still confuse the crap out of me. I've got three related questions that I've been trying to answer to help ME understand constructors a little better. </p>
  
  <p>First, I've been under the impression that constructors need to be named the same as their classes. Consider:</p>
  
  <pre><code>public class Money {
      public Money(long l) {
          this.value = l;
      }
  
      public Money(String s) {
          this.value = toLong(s);
      }
  
      public long getLong() {
          return this.value;
      }
  
      public String getString() {
          return toString(this.value);
      }
  } 
  </code></pre>
  
  <p>I see this as four constructors...correct? So it <em>appears</em> that constructors <em>not</em> named the same as the class which contains them allowable. Can someone confirm that?</p>
  
  <p>Second, I seem to have a block against understanding the set and get methods. Consider:</p>
  
  <pre><code> public class GetSetSample {
       public int getFoo()  {
   return int Foo;
   }
   public void setFoo(int fooValue) {
   int Foo = fooValue;
   } 
  } 
  </code></pre>
  
  <p>Why can't I just do this:</p>
  
  <pre><code>public class getFoo(int fooValue){
       foo=fooValue;
  }
  </code></pre>
  
  <p>and use <code>foo = getFoo(12)</code> from some other class/method? </p>
  
  <p>The third question is a little more esoteric, but will help me conceive of the bigger picture...which is my learning style, and conducive to my ability to trace program flow when debugging. The <code>get</code> and <code>set</code> methods suggest a "to" and "from" relationship to me. e.g., Passing a value "to" a constructor, receiving the result "from" the get method. It seems to me though that the "to" and "from" will change depending on your perspective. I think that any <code>setMethod</code> is setting parameters for an object, even though the variable comes FROM another class or method, and the <code>GetMethod</code> is <code>get</code>ting the resulting object (say, <code>this.foo</code>) with the appropriately <code>set</code> parameter. No matter where the <code>get</code> or <code>set</code> is used, in a main method or a standalone class with a single constructor, 'set' is always associated with sending a parameter and <code>get</code> is always associated with receiving an object with that parameter. Is that a good understanding? or am I missing a vital part?</p>