File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread question-no run() method signature" Watch "Thread question-no run() method signature" New topic
Author

Thread question-no run() method signature

Rob Kiu
Greenhorn

Joined: Feb 02, 2004
Posts: 15
Hi everyone,
Code below compiled, executes and prints out nothing. My question is why b.run(); 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 !!
Rob
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
Bijesh
Sindhur Sat
Greenhorn

Joined: Feb 23, 2004
Posts: 23
Reason:
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.
Sindhur
Rob Kiu
Greenhorn

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
run
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.

Cheers,
Rob
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Thread question-no run() method signature