看板 java 關於我們 聯絡資訊
我查了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
lui:因為運用了多型 ht.keys()回傳一個繼承Enumeration的物件 01/30 16:56
rg550:我看ht.keys()回傳的型態是enumeration 01/30 17:40
rg550:如此是在那邊實作hasMoreElements()的程式碼呢? 01/30 17:43
※ 編輯: rg550 來自: 219.84.27.29 (01/30 17:54)
lui:Hashtable裡的inner class 01/30 19:18
rg550:歐~ 感謝~ 01/31 12:56