Again a simple example on how to use, the ENUM keyword from JDK 1.5 onwards is used to define a selection of items that wont change, for example months, days, name or in this case course titles.
-----------------------------------CODE-----
start.java
// SIMPLE CODE TO DEMONSTRATE THE POWER OF ENUMERATION IN JAVA
public class start
{
public static void main(String args[])
{
///////////////////////////////
//USING A ENHANCED FOR - LOOP//
// test = name of enum - for example CODE1, CODE2
// title = name of course
// code = course code
///////////////////////////////
for(enumTest test: enumTest.values())
{
System.out.printf("%s : %s : %s\n", test,test.getTitle(),test.getCode());
}
}
}
enumTest.java
public enum enumTest
{
CODE1("JAVA Behinners","OIU98"),
CODE2("VB6 Beginners","938493J");
///////////////////////////
//DECLARE FINAL VARIABLES//
//////////////////////////
private final String title;
private final String code;
//////////////////////
//CLASS CONSTRUCTOR///
//////////////////////
enumTest(String NewTitle, String NewCode)
{
title=NewTitle;
code=NewCode;
}
///////////////////////
//GETTERS//
///////////////////////
public String getTitle()
{
return title;
}
public String getCode()
{
return code;
}
}
------------------------------------OUTPUT---------------------------
CODE1 : JAVA Behinners : OIU98
CODE2 : VB6 Beginners : 938493J
No comments:
Post a Comment