Results 1 to 3 of 3
  1. #1
    bugger is offline Senior Member
    Join Date
    Nov 2007
    Posts
    111
    Rep Power
    0

    Default Constructor with enum

    I have the following class:

    Java Code:
    public class GTent{
    	enum ttype{RANGE,LENGTH};
    	int length;
    	ttype blockType;
    	
    	public GTent(int i, int j, ttype t) {
    		
    		this.length= i + j;
    		this.blockType = t;
            }
    In some other class, I want to create an object of it. I am not sure how to supply enum value to the constructor. Please advice.

  2. #2
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    8

    Talking enum and constructors

    Hello bugger.

    Add the public modifier to the definition of your enumerator. Then use the name of your class as you would when you access static members:

    Java Code:
    GTent test = new GTent(0, 0, GTent.ttype.RANGE);
    Hope this helped. ;)
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  3. #3
    bugger is offline Senior Member
    Join Date
    Nov 2007
    Posts
    111
    Rep Power
    0

    Default

    Thanks tim. It worked. I simply imported the enumeration using public modifier.
    Keep posting mate.

Similar Threads

  1. Replies: 0
    Last Post: 12-19-2007, 10:10 AM
  2. Replies: 0
    Last Post: 12-19-2007, 10:01 AM
  3. Enum Iteration
    By A.Russell in forum New To Java
    Replies: 1
    Last Post: 08-15-2007, 01:17 PM
  4. Enum?
    By vgbhagavan in forum Advanced Java
    Replies: 0
    Last Post: 06-14-2007, 03:02 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
  •