Author Topic:   For an object to be a target for a Thread, that object must be of type:
shan
unregistered
posted February 23, 2000 09:23 AM           
thread and runnable are true is 'nt it??

Tony Alicea
sheriff
posted February 23, 2000 11:03 AM             
Either a Thread or a Runnable object; yes.

Jim Yingst
sheriff
posted February 23, 2000 12:49 PM             
Err... how can a Thread have another Thread as its target? I don't see any constructors or methods which achieve this. For comparision, the constructor Thread(Runnable target) makes a runnable object the target for a Thread. But I don't see a Thread(Thread target) anywhere.

maha anna
bartender
posted February 23, 2000 02:22 PM             
Jim,
Do you think the question meant this? What do you say is right.There is no Thread constructor taking a Thread object as an input.But the class java.lang.Thread class itself implements the Runnable interface which means a Thread object can be substituted for an Runnable object right? I checked this with the foll. code. It compiles and prints 'maha'.
regds
maha anna
code:

class MyThread extends Thread {
public void run() {
System.out.println("maha");
}

}
class test {

public static void main(String[] args) {
MyThread mt = new MyThread();
Thread t1 = new Thread(mt);
t1.start();
}
}


Jim Yingst
sheriff
posted February 23, 2000 02:39 PM             
Oops. I missed the obvious. Thanks maha anna!

|