none.
- your code is not valid (
SOP???)
-
Runnable
is an interface (
implements
not
extends
- unless
MyRunnable
is an Interface too, of course.)
and the main reason is that the class
MyMain
will not run because it does not have main function.
BUT when you modify that to be a valid code (with 3 separate classes!):
public class MyMain {
public static MyThread oThread = new MyThread(new MyRunnable());
public static void main(String[] args) {
oThread.start();
}
}
class MyThread extends Thread {
MyThread(Runnable r) {
super(r);
}
@Override
public void run() {
System.out.println("my thread runs.");
}
}
class MyRunnable implements Runnable {
@Override
public void run() {
System.out.print("my runnable runs.");
}
}
The
Thread
is running. Why?
Check the code - it's
overriding
the
run()
method from the
Runnable
.
If you remove the run method from the Thread the runnable's run method is getting it's chance to run.
EDIT: struggled a little with the code highlighting...