Author Topic:   thread
Umesh
ranch hand
posted March 11, 2000 03:45 PM             

public class Whiffler extends Object implements Runnable
{
Thread myT;
public void start()
{
myT = new Thread(this);
}
public void run()
{
while(true()
(
doStuff();
}
System.out.println(Exiting Run");
}
public void doStuff()
{
// some code
}
// some more code...

Assume that above code compile free and also assume that a Java application creates a Whiffler object and calls start[/] method, that no other calls to Whiffler methods are made and that the [b]Thread in this object is the only one the application creates.

Which of the following are true ?
1. The doStuff method will be called repeatedly.
2. The doStuff method will never be executed.
3. The doStuff method will execute at least one time.
4. The statement in line 10 will never be reached.

Answer is 2&4.
Since the statement says that Whiffler oject calls start method, why not answer 1&3.

maha anna
bartender
posted March 11, 2000 04:08 PM             

public void start(){
myT = new Thread(this);
}

The start() method of the Whiffler class just creates a new thread. It is not started yet.In order to start the thread you have call the start() method of the thread ref myT such as myT.start() . Also note that, the public void start() method defined in this Whiffler class is not inherited from Thread class. It's not at all related to starting the thread. It is completely diff. method which happened to have the same name as start() method in Thread class. The Whiffler class is not a thread by itself. It just implements the Runnable interface.
regds
maha anna

Umesh
ranch hand
posted March 11, 2000 04:20 PM             
Thanx....Anna!!!(I came to know u r a she!!....then how come ur name in He.....thinking that it is a Indian name)

|