Here i know that Enumeration is a interface.is interface has the ability of hold data within it.This code i have got from Javatutorialpoint site.please clarifymu doubt.import java.util.Vector;
import java.util.Enumeration;
public class EnumerationTester {
public static void main(String args[]) {
Enumeration days;
Vector dayNames = new Vector();
dayNames.add("Sunday");
dayNames.add("Monday");
dayNames.add("Tuesday");
dayNames.add("Wednesday");
dayNames.add("Thursday");
dayNames.add("Friday");
dayNames.add("Saturday");
days = dayNames.elements();
while (days.hasMoreElements()){
System.out.println(days.nextElement());
}
}
}
解决方案
No, you "know" it wrong. Interface is not something that holds data. Interface is interface. And there is no "doubt" to clarify. It would be good if you explained some doubt, but you just show the code sample, not even written by you. This is not a question, and not a productive way of getting knowledge.
The sample you've looked at is from here: http://www.tutorialspoint.com/java/java_enumeration_interface.htm[^].
(It's too bad you did not provide the link. Do you think that members have nothing more useful to do than searching articles by your code fragments? Please always reference all you quote. After all, failure to do that violates basic rights of the authors of the original content.)
The interface uses in this code sample is this: http://docs.oracle.com/javase/7/docs/api/java/util/Enumeration.html[^].
Everything is explained quite clearly. The purpose of this interface is to provide the construct supporting iteration, "for" loops.
First of all, it's important not to mix up this particular interface with enumeration types: https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html[^].
Most likely, the only thing which can help you would be systematic study of the language and technology, starting from the fundamentals. You need to learn very well what are types and instances, variables and objects, what is interface, how interfaces work, and a lot more.
—SA