[問題] 關於enumeration的疑問

看板java作者 (杰克)時間15年前 (2011/01/30 15:55), 編輯推噓2(203)
留言5則, 2人參與, 最新討論串1/1
我查了enumeration這個類別 他是屬於interface 介面類別 那麼介面類別中的method 不是應該都沒有程式碼? 那麼 請問以下的程式是為何可以running呢? import java.util.*; class Ex16_5 { public static void main(String[] args) { Hashtable ht = new Hashtable(); ht.put("Server", new String("163.15.40.242")); ht.put("Client1", new String("163.15.40.243")); ht.put("Client2", new String("163.15.40.244")); Enumeration enValue = ht.elements(); while(enValue.hasMoreElements()) { String sValue = (String) enValue.nextElement(); System.out.println("enValue = " + sValue); } Enumeration enKey = ht.keys(); while(enKey.hasMoreElements()) { String sKey = (String) enKey.nextElement(); System.out.println("enKey = " + sKey); } } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.84.27.29

01/30 16:56, , 1F
因為運用了多型 ht.keys()回傳一個繼承Enumeration的物件
01/30 16:56, 1F

01/30 17:40, , 2F
我看ht.keys()回傳的型態是enumeration
01/30 17:40, 2F

01/30 17:43, , 3F
如此是在那邊實作hasMoreElements()的程式碼呢?
01/30 17:43, 3F
※ 編輯: rg550 來自: 219.84.27.29 (01/30 17:54)

01/30 19:18, , 4F
Hashtable裡的inner class
01/30 19:18, 4F

01/31 12:56, , 5F
歐~ 感謝~
01/31 12:56, 5F
文章代碼(AID): #1DHHbwiS (java)