Results 1 to 2 of 2

Thread: Enumerations

  1. #1
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Enumerations

    Java Code:
    enum Bool {
    		TRUE(1), FALSE(0);
    		private int value;
    
    		private Bool(int value) {
    			this.value = value;
    		}
    
    		int getValue() {
    			return value;
    		}
    	}
    public static void main(String[] args){
    System.out.println(Bool.TRUE.getValue());      // HOW IT WORKS ???
    
    }
    can do it by Bool b = Bool.TRUE; System.out.println(b.getValue()); Is the above line creates bool object automatically ?
    Last edited by allaudin; 08-03-2013 at 03:58 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Enumerations

    Enum constants are static; they are created when the class is loaded.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Ho to work with enumerations in java
    By zizou147 in forum Advanced Java
    Replies: 0
    Last Post: 03-22-2008, 12:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •