Which one statement is true for the following code?
1. class MyList extends java.util.Vector 2. implements Runnable { 3. public void run(String message) { 4. System.out.println("in run() method: " + 5. message); /*from w w w . j a va2 s . c o m*/ 6. } 7. } 8. 9. class MyListTest { 10. public static void main(String args[]) { 12. MyList g = new MyList(); 13. Thread t = new Thread(g); 14. t.start(); 15. } 16. }
MyList
does not correctly implement the Runnable interface. A.
The Runnable interface defines a run()
method with void return type and no parameters.
The method given in the problem has a String parameter, so the compiler will complain that class MyList
does not define void run()
from interface Runnable.
B is wrong, because you can pass a parameter to a thread's constructor; the parameter becomes the thread's target.
C, D, and E are wrong.