• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread

 
Aruna Balasuriya
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could you explain clearly...
 
Aruna Balasuriya
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread implements Runnable.
 
Chitti Ruddarraju
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
default constructors for Thread class and Mythread will take care of your object...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic