title: Using object as parameters in java
body: <pre><code>class Test {
  
  int a, b;
  
  Test (int i,int j) 
  {
      a=i;
      b=j;
      System.out.println("a is " + a);
  }
  boolean equalto(Test o)
  {
  
  if (o.a == a &amp;&amp; o.b == b )
      return true;
  else return false;
  
  }
       }
  
  class PassObj {
  
  public static void main(String[] args) {
  
      Test ob2 = new Test(100,22);
      Test ob3 = new Test(-1 ,-1);
      Test ob1 = new Test(100 ,22) ;
  
  System.out.println(ob1.equalto(ob2));
  System.out.println(ob1.equalto(ob3));
  
  
  
  }
      }
  </code></pre>
  
  <p>In the above code may I know how  if condition is working.
  say for 1st print statement in if statement ob2.a is compared with "a" i.e 100==a</p>
  
  <p>my doubt is what is the value of "a" it is taking to compare and how ? I have tried to print that "a" value  before print statement is executed and I understood that when object is created and initiated those 3 values of "a" is getting printed as 100, -1 and 100.</p>
  
  <p>Does ob1.equalto(ob2) calls constructor again ? if so then in my output shouldn't "a" get printed again. I am new to OOP and not clear with this concept.</p>
  
  <p>My doubt is which "a" it will take when it is comparing for print statement 1 and 2 and how can I print only those 2 "a"</p>
  
  <p>output I am getting now:</p>
  
  <pre><code>a is 100
  a is -1
  a is 100
  true
  false
  </code></pre>