Note that this method is not Abstract in the Thread Class. So you need not necessarily override it. But the Thread class version
doesn't do anything. It is just empty implementation.
Because:
1 - If your thread extends from Thread class, and if want that your class do some work, you must override the run method.
2 - Also the run's Thread Class is not a empty method, there is some code inside there that is really important to know.
So if you do like this:
new Thread( new X() ).run(); // It calls the run() of object that is inside Thread's constructor - . // same thread, so if you code something in X's run(), it will be executed !!
new Thread( new X()).start(); // Correct way, X's run() runs but in another Thread
public void run() {
if (target != null) {
target.run();
}
}
So you could say that it is not totally empty but, practically, it is not really doing anything because if you extend Thread, your target will probably be null.
So new MyThread().start(); will basically be doing nothing.
But you are right that the explanation should make that clear.
A call to start() returns immediately but before returning,
it internally causes a call to the run method of either the Thread class (if the thread was created by doing new ClassThatExtendsThread()) or of the Runnable class (if the thread was created by doing new Thread( classImplementingRunnable);)
___________________________________________
Question: For the last sentence, should the word class be changed to interface?
-----
A call to start() returns immediately but before returning,
it internally causes a call to the run method of either the Thread class (if the thread was created by doing new ClassThatExtendsThread()) or of the Runnable interface (if the thread was created by doing new Thread( classImplementingRunnable);)
Not really. Runnable is indeed an interface but what it is trying to say by "Runnable class" is "a class that is-a Runnable" i.e. a class that implements Runnable. Similarly, by "Thread class", it means a class that is-a Thread i.e. a class that extends Thread.
However, to avoid the confusion, I am changing it to instance.
HTH,
Paul.