This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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: 20029

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: 1776

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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: mysterious Mr. Thread(), Mr. run() and Mr. start()
It's not a secret anymore!