Advertisement
Kvarz

enum - simple example

Nov 16th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1.    
  2.     enum Apple {
  3.        RED("drink"), GREEN("cook");
  4.        
  5.        private final String color;    
  6.        
  7.        Apple(String colorNew) {    
  8.           this.color = colorNew;
  9.        }
  10.        
  11.        String getColor() {    
  12.           return color;
  13.        }
  14.     }
  15.      
  16.     public class EnumTest3 {
  17.      
  18.        public static void main(String[] args) {
  19.          
  20.           for (Apple a : Apple.values()) {
  21.               //inside println we can type "a.name()" to get name
  22.               //or simply type "a" as follows:
  23.              System.out.println(a +" apples are used to "+ a.getColor());
  24.           }
  25.        }
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement