1

Possible Duplicate:
Java: “implements Runnable” vs. “extends Thread”

When should you use:

    class MyThread extends Thread {
    public void run() {
        System.out.println("Important job running in MyThread");
    }

    public void run(String s) {
        System.out.println("String in run is " + s);
    }
}

over:

    class MyRunnable implements Runnable {
    public void run() {
        System.out.println("Important job running in MyRunnable");
    }
}

Obviously we instantiate these differently but is there any difference once they are created?

Community
  • 1
  • 1
Michael W
  • 3,515
  • 8
  • 39
  • 62

1 Answers1

0

Thread is a class that implements Runnable interface. Essentially, that means that this is allowable:

Runnable runnable = new MyThread();
runnable.run();

By implementing a Runnable, you're essentially have to implement the run() method for the Thread to execute it.

Other than that, I don't know what you're really asking.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228