作者rg550 (杰克)
看板java
标题[问题] 关於enumeration的疑问
时间Sun Jan 30 15:55:36 2011
我查了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
1F:推 lui:因为运用了多型 ht.keys()回传一个继承Enumeration的物件 01/30 16:56
2F:→ rg550:我看ht.keys()回传的型态是enumeration 01/30 17:40
3F:→ rg550:如此是在那边实作hasMoreElements()的程式码呢? 01/30 17:43
※ 编辑: rg550 来自: 219.84.27.29 (01/30 17:54)
4F:推 lui:Hashtable里的inner class 01/30 19:18
5F:→ rg550:欧~ 感谢~ 01/31 12:56