title: What is the use of constructor in JAVA when you can initialize the instance variable at the time of it's declaration?
body: <p>1st program without constructor:</p>
  <pre><code>public class Sample1 {
      int a=9;
      public static void main(String args[]) {
          Sample1 obj = new Sample1();  // I know this is a default constructor
          System.out.println(obj.a);
      }
  }
  </code></pre>
  <p>Output: 9</p>
  <p>2nd program with constructor:</p>
  <pre><code>public class Sample1 {
      int a;
      Sample1(){
          a=9;
      }
      public static void main(String args[]) {
          Sample1 obj = new Sample1();
          System.out.println(obj.a);
      }
  }
  </code></pre>
  <p>Output: 9</p>
  <p>If both the things give same output then what's the use of taking the pain to declare constructor?</p>