File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes mysterious Mr. Thread(), Mr. run() and Mr. start() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "mysterious Mr. Thread(), Mr. run() and Mr. start()" Watch "mysterious Mr. Thread(), Mr. run() and Mr. start()" New topic

mysterious Mr. Thread(), Mr. run() and Mr. start()

Marcus Deviln
Ranch Hand

Joined: Jan 29, 2009
Posts: 39

...and the answer:

(d) The program will compile without errors and will print out |R1b| once and |R2| twice, in some order, every time the program is run.

Why does "|R2|" print if it doesn't have a run() method? or better yet why does it not need its own run() method for it to print out? Why will "|R2|" print out twice? The author says it will print out in some order- which makes me wonder how is it that it can print in random order? I thought the constructors will be used as they appear from the top down like an instance initializer block.

+Deviln+ The power of JAVA compels you!
Henry Wong

Joined: Sep 28, 2004
Posts: 18532

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
There are some typos and where is R2 defined?
Can you clean up your code a bit? Thanks.
Jim ... ...

Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1659

1. You still haven't quoted your source. Please do so.
2. There's a compiler error on line 10

When you do things right, people won't be sure you've done anything at all.
I agree. Here's the link:
subject: mysterious Mr. Thread(), Mr. run() and Mr. start()
Similar Threads
Threads blocking on static method.... or do they?
wait() releases all locks?
Exercise 13.6 in - A Programmer's Guide to Java SCJP Certification - 3rd Ed
Runnable to Thread Casting
synchronize on local variables of an object reference