my dog learned polymorphism
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "overriding methods: doubt" Watch "overriding methods: doubt" New topic

overriding methods: doubt

rijagu chan

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

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
I agree. Here's the link:
subject: overriding methods: doubt
It's not a secret anymore!