Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt with run method..

 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks..
 
Dean Jones
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic