隨筆-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, 說明實現(xiàn)他的類可以不處理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)  編輯  收藏 所屬分類: 工作日志

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 合作市| 阿图什市| 淮滨县| 南乐县| 台江县| 神木县| 蛟河市| 若羌县| 凤台县| 云梦县| 五指山市| 客服| 奉新县| 潞西市| 池州市| 阜宁县| 通榆县| 苏尼特右旗| 富川| 澜沧| 镇原县| 奉节县| 旌德县| 明星| 安多县| 福鼎市| 皋兰县| 泰兴市| 高陵县| 鄂伦春自治旗| 平顶山市| 香河县| 福安市| 资源县| 沁源县| 明光市| 栾川县| 宣城市| 隆子县| 德格县| 湾仔区|