Switch to full style
General Java code examples
Post a reply

Define enum in java

Thu Jan 29, 2009 1:50 am

Define enum in java :

Enum is a special type of classes. enum type put restriction on the instance values.

Code:


public enum myCars{
    
HONDA,BMW,TOYOTA
};

 


Code:
public class Main {
 
    public static 
void main(String[] args) {
        
// TODO code application logic here
        
        
myCars currentcar=myCars.BMW;
        
        
System.out.println("My Current Cars : "myCars.BMW);
        
        
    }

}
 


you will need to create a file with the same name of the enum like the case of any java class.



Post a reply
  Related Posts  to : Define enum in java
 Define Enum inside a class     -  
 Java enum example     -  
 extending enum in java     -  
 Enum Declaration     -  
 how to use enum in jaxb unmarshalling     -  
 Passing Enum as Type Parameter to method     -  
 Define template in C++     -  
 Define statement     -  
 Define new namespaces in C++     -  
 how to Define abstract class in php     -