I saw this question in a book at the bookstore. I thought a
thread was invoked with the start() method, not the run() method. However, all the choices compile and run an infinite loop. What's the answer and why?
1. public class T implements Runnable {
2. public static void main (
String[] args) {
3. //insert code here
4. }
5.
6. public void run() {
7. int i=0, j=0;
8. for (;
{
9. i++;
10. j++;
11. System.out.println(i+", "+j);
12. }
13. }
14. }
You want to cause execution of the run method in a new thread of execution. Which line(s) should be added to the main method in line 3?
A. Thread t = new Thread(T).start();
B. Thread t = new Thread(T).run();
C. T t = new T();
new Thread(t).start;
D. T t = new T();
new Thread(t).run;
E. T t = new T();
t.run();