This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

Sudipta Das
Greenhorn

Joined: Apr 05, 2001
Posts: 18
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
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.
 
Consider Paul's rocket mass heater.
 
subject: Threads
 
Similar Threads
JQuest Cert Simulation Question
JQuest
Thread Question
Another Question From JQuest Mock Exam...
A suggestion for list of Mock Questions