title: creating threads through annomyous inner class
body: <p>I was developing the code of creating a thread but without extending the thread class or implementing the runnable interface , that is through anonymous inner classes ..</p>
  
  <pre><code>public class Mythread3 {
      public static void main(String... a) {
  
          Thread th = new Thread() {
  
              public synchronized void run() {
                  for (int i = 0; i &lt; 20; i++) {
                      try {
                          Thread.sleep(1000);
  
                          System.out.print(i + "\n" + "..");
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                  }
  
              }
  
          };
  
          th.start();
          Thread y = new Thread();
          y.start();
  
      }
  }
  </code></pre>
  
  <p>Now please advise me can I create child threads also with the same approach..!! what I have tried is that...</p>
  
  <pre><code>public class Mythread3 {
      public static void main(String... a) {
  
          Thread th = new Thread() {
  
              public synchronized void run() {
                  for (int i = 0; i &lt; 20; i++) {
                      try {
                          Thread.sleep(1000);
  
                          System.out.print(i + "\n" + "..");
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                  }
  
              }
  
          };
  
          Thread th1 = new Thread() {
  
              public synchronized void run() {
                  for (int i = 0; i &lt; 20; i++) {
                      try {
                          Thread.sleep(1000);
  
                          System.out.print(i + "\n" + "..");
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                  }
  
              }
  
          };
          th.start();
          try {
              th.join();
          } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          th1.start();
  
      }
  }
  </code></pre>
  
  <p>But there are two run() methods in it, I think this not practical..please advise..!</p>