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 Doubt with run method.. 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 "Doubt with run method.." Watch "Doubt with run method.." New topic
Author

Doubt with run method..

Gitesh Ramchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 274
source: Dan Chisholm



What is the result of attempting to compile and run the program?

Ans:e
Doubt: is the answer e, because the run method cannot throw any exception?


Thanks,
Gitesh
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
you are correct, since the run method does not declare any throw (as specified in the API). When you override a method (from Thread here) you can only throw the same Exceptions or less.

This way, someone using your class assuming that it is a Thread, can use the run method as expected

Regards,
Alex
Gitesh Ramchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 274
thanks..
Dean Jones
Ranch Hand

Joined: Dec 29, 2007
Posts: 129
Even if the original method which have been overriden,had thrown the same exception, it is no where handled. Would that not give a compile time error unless the main class, from which it is called also declared or handled the exception?
 
 
subject: Doubt with run method..