Originally posted by Arpana Rai:
About Q.3) pm1.start(); calls the overriding run() method in subclass.If you do not override the run() method in your class it call the run() method of thread class.
To learn more go through the same discussion had before ....https://coderanch.com/t/239859/java-programmer-SCJP/certification/Dan-thread-exam
Hope this helps you
regds
Arpana
[ November 14, 2002: Message edited by: Arpana Rai ]
clarification -
to start any thread, we call start() method on the Thread instance:
ex. testThread.start();
From "Java2, Sun Certified Programmer for
Java 2, Study Guide" by Syngress/Osborne I read the following:
In the case of a Runnable target, its run method is not called directly, but it is called by the default run method of the Thread instance."
"
I guess what I was trying to clarify is that the above comment applies to both subclasses of Thread class and also Objects that implement the Runnable interface.
-------------------------
let's say you have the class I mentioned in the above code. Instead of calling pm1.start(); we call pm1.run(); instead (as was the code when Marcus wrote the
test question).
If we call pm1.run(); we will be running in the main thread and the method "run()" behaves like a normal instance method (inside main's thread of execution).
So if we call pm1.start(); instead, something must occur to create a separate thread of execution before the contents of run() method of Pmcraven gets called, and the run() method then executes within it's own thread.
-----------------------------------
Marcus Green's exam had several good questions which really forces you to learn the ins and outs of these start and run calls!