This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Implementing Interface methods in implementing class.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Implementing Interface methods in implementing class...." Watch "Implementing Interface methods in implementing class...." New topic
Author

Implementing Interface methods in implementing class....

Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

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!~


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

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!
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
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.


SCJP 1.6 96%
Jeevan Reddy
Ranch Hand

Joined: Nov 10, 2009
Posts: 142
Thanks Neha for the clarification.

SCJP 1.6 (94%)
http://faq.javaranch.com/java/JspFaq
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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).


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Thanks Nega Daga & Wouter Oet. It's clear now. Thanks a lot......
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Implementing Interface methods in implementing class....
 
Similar Threads
Switch block best practices
Can an interface support multiple inheritance?
similar named methods in interface
java.rmi.RemoteException
try block