This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread question-no run() method signature Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread question-no run() method signature" Watch "Thread question-no run() method signature" New topic

Thread question-no run() method signature

Rob Kiu

Joined: Feb 02, 2004
Posts: 15
Hi everyone,
Code below compiled, executes and prints out nothing. My question is why; is OK when it was not overridden and class Bground does not implements Runnable. Thought it'll give compile error eg: if we call a method say b.test(); but did not define the method signature in the class eg void test(){};
Appreciate any help, thanks !!
From Marcus Green Mock : Question Bank Id:106, code added:b.test(); & comments
Bijesh Krishnadas
Ranch Hand

Joined: Aug 08, 2002
Posts: 31
run() is a non-abstract method in Thread. Which is why u dont need to override the method in your class
Sindhur Sat

Joined: Feb 23, 2004
Posts: 23
Thread is a non abstract class that implements Runnable and run() is a public abstract method in Runnable; so guess what, Thread is forced to implement run() method; if you want you can override it in your extended class;In that case your run() method would have been executed in a new thread instead of the blank run() method of the Thread class.
Rob Kiu

Joined: Feb 02, 2004
Posts: 15
Dear Bijesh, Sindhu,
Thanks for clearing that up. Look up the API to confirm, yes indeed Thread has a public void run method, whereas I thought only Runnable has the run method, so the code I quoted works!
From 1.4.2 API
public void run()
If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.
Subclasses of Thread should override this method.

I agree. Here's the link:
subject: Thread question-no run() method signature
It's not a secret anymore!