When you implement an interface method, you are allowed to declare that you throw fewer exceptions than what is specified in the interface.
When you call new apples().meth()
, you call meth()
on the apples
instance. The compiler knows that it doesn't throw anything, so you're fine.
You made:
BadInterface foo = new apples();
then you will need to catch the exception declared in the interface, because the compiler only knows about this with the BadInterface
instance.
source share