隨筆-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 閱讀(183) 評論(0)  編輯  收藏 所屬分類: 工作日志
          主站蜘蛛池模板: 呈贡县| 黄平县| 加查县| 北碚区| 印江| 清原| 清水县| 南投市| 随州市| 凌源市| 金沙县| 乌兰县| 合肥市| 德安县| 海丰县| 巩留县| 禹州市| 荔波县| 施甸县| 康马县| 泸溪县| 天等县| 平南县| 双牌县| 含山县| 固镇县| 东乌| 北碚区| 沐川县| 珲春市| 托里县| 黄梅县| 连云港市| 黄浦区| 蛟河市| 长岭县| 昌宁县| 玛纳斯县| 玉龙| 宁化县| 荔波县|