This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes overriding methods: doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "overriding methods: doubt" Watch "overriding methods: doubt" New topic
Author

overriding methods: doubt

rijagu chan
Greenhorn

Joined: Apr 10, 2000
Posts: 7
One of the answers is the overiding method must not throw any exceptions that may not be thrown by the overridden method.
My question is what about a RuntimeException. What if I throw an ArithmeticException explicitly only in the overiding method.
void overriddenMethod() { }
void overridingMethod() throws ArithmeticException { }
Uvnik Gupta
Ranch Hand

Joined: Jul 24, 2000
Posts: 32
The statement is a bit ambiguous. If it means only checked exceptions then it's correct but if it means any kind of exception, it's wrong.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
A RuntimeException can be thrown by the overridden method or the overriding method. The statement only talks about exceptions that can not be thrown by the overridden class, and so it has nothing to with RuntimeExceptions (or Errors for that matter). The statement is definitely true.


"I'm not back." - Bill Harding, Twister
 
jQuery in Action, 3rd edition
 
subject: overriding methods: doubt
 
It's not a secret anymore!