title: thread and creating object
body: <p>I am trying to learn about thread and find some examples in the internet. This is a java class that output "hello, world" every 3 seconds. But I have a feeling that the part about creating a Runable object is redundant.</p>
  
  <p>Instead of writing </p>
  
  <pre><code>Runnable r = new Runnable(){ public void run(){...some actions...}}; 
  </code></pre>
  
  <p>Can I put the method <code>run()</code> somewhere else for easy reading?</p>
  
  <p>This is what I have:</p>
  
  <pre><code>public class TickTock extends Thread {
      public static void main (String[] arg){
          Runnable r = new Runnable(){
              public void run(){
                  try{
                      while (true) {
                          Thread.sleep(3000);
                          System.out.println("Hello, world!");
                      }
                  } catch (InterruptedException iex) {
                      System.err.println("Message printer interrupted");
                  }
              }
          };
        Thread thr = new Thread(r);
        thr.start();
  }
  </code></pre>
  
  <p>And this is what I want to accomplish</p>
  
  <pre><code>public static void main (String[] arg){ 
            Runnable r = new Runnable() //so no run() method here, 
                                    //but where should I put run()
            Thread thr = new Thread(r);
            thr.start();
      }
  </code></pre>