wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes start() kicks start() but not run() why? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "start() kicks start() but not run() why?" Watch "start() kicks start() but not run() why?" New topic
Author

start() kicks start() but not run() why?

srinivas bolloju
Ranch Hand

Joined: Jan 23, 2001
Posts: 112
i was experimenting on this small program,i found out that start() below kicks off start() and not run(), ,can anybody pls explain me this...
thanks in advance
public class startRun extends Thread{
public static void main(String argv[]){
startRun b = new startRun();
//b.run();
b.start();
}
public void start(){
//run();
for (int i = 0; i <10; i++){
System.out.println("Value of i = " + i);
}
}
public void run(){
System.out.println("im in run");
}
}


please use the [code][/code] tags when showing code. visit <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" target="_blank" rel="nofollow">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page</a> ,for more details
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
When extending Thread, you just have to provide a body for the run() method, but do not override the native start() method otherwise your thread won't run. Try this:


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Deepali Pate
Ranch Hand

Joined: Mar 20, 2002
Posts: 114
You are extending the Thread class and overriding the start() method from the Thread class. The default start() of Thread class has an inbuilt script which would call run().
But now since u are overriding the default start() the overridden start() is called and it has no code to invoke the run().
This is the reason i guess.
 
 
subject: start() kicks start() but not run() why?