June 2004
Intermediate to advanced
848 pages
21h 28m
English
There are two ways to obtain a new thread of control in Java. Either extend the Thread class, or write a class to implement the java.lang.Runnable interface and use it in the Thread constructor. The first way can be used only if your class doesn't already extend some other class (because Java disallows multiple parents).
Extend class java.lang.Thread and override run():
class Plum extends Thread { public void run() { /* more code */ }}Plum P = new Plum();P.start();
or
Implement the Runnable interface (the class Thread itself is an implementation of Runnable), and use that class in the Thread constructor: ...
Read now
Unlock full access