The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread Doubts 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 "Thread Doubts" Watch "Thread Doubts" New topic

Thread Doubts

Micheal John
Ranch Hand

Joined: Nov 01, 2006
Posts: 344
From web page

How the output is a? pls expalain

Micheal John
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
Henry Wong

Joined: Sep 28, 2004
Posts: 20526

You are creating an A object, and calling it's start() method -- which in turns calls the run() method. This run() method prints the "A".

The A method does set the runnable of the object to B, but since you overridden the run() method of A, it doesn't call it anymore.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ignacio Cavero

Joined: Dec 10, 2006
Posts: 4
You are using the new A(Thread t) constructor for A that it is inheriting from the Thread class. Because of that, without noticing you are starting the run method of the runable Object B instead of the run method of A.
I agree. Here's the link:
subject: Thread Doubts
It's not a secret anymore!