This question is also from the mock exam http://jquest.webjump.com. The correct answers are given as 'a' & 'b'. Is only 'b' not enough ? Please advise me. What can you write at the comment //A in the following code so that this program writes the word "running" to the standard output? 1. class RunTest implements Runnable { 2. public static void main(String args[]) { 3. RunTest rt = new RunTest(); 4. Thread t = new Thread(rt); 5. //A 6. } 7. public void run() { 8. System.out.println("running"); 9. } 10. void go() { 11. start(1); 12. } 13. void start(int i) { 14. } 15. } Select all valid answers.
Ans : a. System.out.println("running"); b. t.start(); c. rt.start(); d. rt.start(1);
Sean Casey
Ranch Hand
Joined: Dec 16, 2000
Posts: 625
posted
0
In this code answer b is fine. You are implementing the interface Runnable which contains one method to override public void run(). In this definition the run method is properly overridden. A thread object is created and given an instance of the class implementing runnable as it's target, so t.start will move the thread to the runnable state.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.