aspose file tools*
The moose likes Java in General and the fly likes Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Thread" Watch "Thread" New topic
Author

Thread

Aruna Balasuriya
Ranch Hand

Joined: Nov 14, 2009
Posts: 44
Following Code compile and runs but in Thread class threre are constructor to accept Thread(Thread arg).Please Explain


public class MyThread extends Thread{

public static void main(String[] args) {

MyThread t = new MyThread();
Thread x = new Thread(t);
x.start(); }


public void run(){

for(int i=0;i<3;++i){System.out.print(i+"..");}



}

}
Aruna Balasuriya
Ranch Hand

Joined: Nov 14, 2009
Posts: 44
Aruna Balasuriya wrote:are constructor to accept Thread(Thread arg).



I made a mistake it should be as follows

are no constructor to accept Thread(Thread arg).
Chitti Ruddarraju
Greenhorn

Joined: Oct 19, 2009
Posts: 7
could you explain clearly...
Aruna Balasuriya
Ranch Hand

Joined: Nov 14, 2009
Posts: 44
In my code

Thrad x = new Thread(t);

Here the t is type MyThread .MyThread is a Thread as it extends class Thread. Here we are Passing a Thread object to the Thread constructor but in the Thread
class thre are no constructor to accept Thread object as a parameter. But the code compiles and runs ???
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Thread implements Runnable.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Chitti Ruddarraju
Greenhorn

Joined: Oct 19, 2009
Posts: 7
default constructors for Thread class and Mythread will take care of your object...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread