Forums Register Login

Implementing Interface methods in implementing class....

+Pie Number of slices to send: Send
The throws clauses about Exceptions in the interface's methods must exactly match the throws clauses of the implementing methods. That means, we can't even declare the implemented methods as subclass of that Exception. Please confirm, I got it from a Note. Thanks in Advanced!~
+Pie Number of slices to send: Send
In K&B's book, It's said that, A nonabstract implementing class must not declare any new checked exceptions for an implementation method. That means, We can't declare a subclass type Exception in the method declaration. Please confirm!
+Pie Number of slices to send: Send
Its not like that,
always remember overriding methods cannot declare newer or broader checked exceptions.
example:


here version 1,2 and 5 are allowed but version 3 and 4 are not allowed.
+Pie Number of slices to send: Send
Thanks Neha for the clarification.
+Pie Number of slices to send: Send
An implementation cannot throw new checked exceptions or broader checked exceptions. An implementation can as Neha demonstrated with her example throw a smaller exception (FileNotFoundException vs IOException). Of course can an implementation throw new RuntimeExceptions (lowercase T).
+Pie Number of slices to send: Send
Thanks Nega Daga & Wouter Oet. It's clear now. Thanks a lot......
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1160 times.
Similar Threads
Can an interface support multiple inheritance?
Switch block best practices
try block
java.rmi.RemoteException
similar named methods in interface
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 23:21:00.