Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JQ+: Question ID :960680824810

 
Rodney Woodruff
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question ID :960680824810
An overriding method can declare ArithmaticException in it's throws clause even if the overridden method does not have any throws clause.
True or False.
I chose "False". I must admit, wording is really confusing. Can someone clarify this for me? Thanks alot.
 
Steven Wong
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Question ID :960680824810
An overriding method can declare ArithmaticException in it's throws clause even if the overridden method does not have any throws clause.
True or False.

Hi, the answer is True. Because the ArithmeticException is an unchecked exception(runtime exception) and thus does not need to be caught or handled.
Clement
 
Rodney Woodruff
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Clement! The wording was really confusing. I get it now. I just wish that they could have worded it a little better.
 
Gautam Sewani
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does that mean that there are no restrictions on an overriding method in the throws clause incase of unchecked exceptions?
If the overriden method does not specify any unchecked exceptions,still the overriding method can specify them in its throws clause.
Is this right?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are no rules based on unchecked exceptions. That's why they're called "unchecked" exceptions. In fact, even if a method declares that it throws an unchecked exception, the invoking method need not handle it.
This code compiles and runs fine:

Corey
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic