title: Deadlock error is not occuring in this code?
body: <p>Take a look at this code . When a thread acquires a synchronized method in object x and another thread acquires synchronized method on object y , x cant call synchronized method on object y. and y cant call sync method on x . This is the theory that i learned in book . Now look at this code</p>
  
  <pre><code>import java.io.*;
  
  class classx
  {
      synchronized void method_on_x()
      {
          System.out.println("method on class x");
      }
  }
  
  class classy
  {
      synchronized void method_on_y()
      {
          System.out.println("method on class y");
      }
  }
  
  class accessx implements Runnable
  {
      classx cx1;
      classy cy1;
      Thread t;
  
      public accessx(classx cx, classy cy)
      {
          t = new Thread(this);
          cx1 = cx;
          cy1 = cy;
          t.start();
      }
  
      public void run()
      {
          cx1.method_on_x();
          cy1.method_on_y();
      }
  }
  
  class accessy implements Runnable
  {
      classx cx1;
      classy cy1;
      Thread t;
  
      public accessy(classx cx, classy cy)
      {
          t = new Thread(this);
          cx1 = cx;
          cy1 = cy;
          t.start();
      }
  
      public void run()
      {
          cy1.method_on_y();
          cx1.method_on_x();
      }
  }
  
  class multizync
  {
      public static void main(String args[])
      {
          classx c1 = new classx();
          classy c2 = new classy();
          accessx a1 = new accessx(c1, c2);
          accessy a2 = new accessy(c1, c2);
          try
          {
              a1.t.join();
              a2.t.join();
          }
          catch(Exception e)
          {
              System.out.println(e);
          }
          System.out.println("mAIN tHREAD eXECUTION cOMPLETED");
      }
  }
  </code></pre>
  
  <p>This code creates two thread classes accessx and accessy which calls two synchronized methods each on its own instance.how can it happen. When accessx thread has </p>
  
  <pre><code>synchronized method_on_x 
  </code></pre>
  
  <p>it cant call</p>
  
  <pre><code>synchronized method_on_y 
  </code></pre>
  
  <p>which accessy has isn't it. Then why dont i get the error.</p>