随笔-14  评论-1  文章-4  trackbacks-0

Today , research Interface, and get the following conclusion:

1 public  interface Inface {
2           public   void  a()  throws  Exception;
3           public   void  b() ;
4 }

A)
public class Test implements Inface{
       public void a(){
       }
       public void b(){
       }
}
correct!
B)
public class Test implements Inface{
       public void a() throws Exception{
       }
       public void b(){
       }
}
correct!
C)
public class Test implements Inface{
       public void a() throws Exception{
       }
       public void b()throws Exception{
       }
}
Wrong!
接口方法 a) throws Exception, 说明实现他的类可以不处理Exception, 把Exception 向上抛, 也可以处理Exception,therefore A) is ok.B) is ok also.  But C) method b() in Test class don't have to catch Exception, but its interface Inface define b() must handle Exception if have Exception, so C) is wrong.


posted on 2007-03-18 23:44 大胃王的BLOG 阅读(165) 评论(0)  编辑  收藏 所属分类: 工作日志

只有注册用户登录后才能发表评论。


网站导航: