This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Originally posted by Chandra Bhatt: quote: Ummm... So it can be overloaded.
What would we miss if we overloaded start(); Wont calling start() on thread lose its meaning. It should have been final as I think...
Whoops... I see you quoted my mistaken "overloaded" in the few seconds before I corrected it to "overridden" (and it looks like you didn't notice either ). Sorry, I haven't had enough caffeine today.
Anyway, what if we want start() to do something in addition to starting the thread? That is, do some stuff, and then call super.start()? [ March 31, 2007: Message edited by: marc weber ]
Joined: Feb 28, 2007
I see you quoted my "overloaded" in the minute or two before I corrected it to, "overridden" (and it looks like you didn't notice either ).
Hey marc! That's perfect guess, I didn't notice; I felt it was "overridden". But we got our answer out of you, "perform some prior operations if required and call super.start()" Great!
Thanks and Regards, cmbhatt
Joined: Feb 03, 2007
Thanks for Your replies, especially Marc.
Joined: Feb 03, 2007
I agree with your explanation. But can't such a thing be done inside the run method( i mean whatever initializations need be performed )?Is there any particular loss in case by not having start as final?
Originally posted by vishal shekhar: But can't such a thing be done inside the run method( i mean whatever initializations need be performed )?Is there any particular loss in case by not having start as final?
That goes to the difference between extending Thread and implementing Runnable (which is talked about in detail here). In most cases it's sufficient to implement Runnable (in which case you obviously wouldn't need start to be overridable), but sometimes (rarely) you actually want to alter the behavior of the Thread class, in which case it may be vital to be able to override it. [ June 29, 2007: Message edited by: Ulf Dittmer ]