Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Liutauras Vilda
Paul Clapham
Sheriffs:
paul wheaton
Tim Cooke
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Piet Souris
Bartenders:
Mike London
Forum:
Programmer Certification (OCPJP)
Thread: start() and run() defined, which one happens?
Zac Roberts
Ranch Hand
Posts: 82
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I saw something kindof like this in the JQ+ Exam 3, anyone understand why the run method does not run?
public class ThreadStarter extends Thread { public static void main(String args[]) { ThreadStarter t = new ThreadStarter(); t.start(); } public void run() { System.out.println("Run Method"); } public void start() { System.out.println("Start Method"); } }
This code prints "Start Method". But if I comment out the start method, It prints "Run Method".
Zac Roberts<br />SCJP2
Roy Ben Ami
Ranch Hand
Posts: 732
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
the reason is the u overide the start method in your new class.
so the real start method in
thread
(the one that supposed to start the thread and run it) is not getting called.
Shivaji Marathe
Ranch Hand
Posts: 203
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Try to call the the start method of the ancestor like this and you shall see otputs from both the println statements
public class Foo extends Thread { public static void main(String args[]) { Foo t = new Foo(); t.start(); } public void run() { System.out.println("Run Method"); } public void start() { System.out.println("Start Method"); super.start(); } }
Zac Roberts
Ranch Hand
Posts: 82
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks to both of you... good explanations. Now, lets hope I get that question on the exam!
Zac Roberts<br />SCJP2
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Using static variable to start and stop a thread
Thread running behaviour
Creating multiple children threads
Threads doubt??
start() and run()
More...