File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic


Sudipta Das

Joined: Apr 05, 2001
Posts: 18
This question is also from the mock exam 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.
Don't get me started about those stupid light bulbs.
subject: Threads
It's not a secret anymore!