Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-02-2008, 05:03 PM
Senior Member
 
Join Date: Nov 2007
Posts: 111
Rep Power: 0
bugger is on a distinguished road
Default Constructor with enum
I have the following class:

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.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 01-03-2008, 11:40 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 410
Rep Power: 3
tim is on a distinguished road
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:

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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-04-2008, 12:21 PM
Senior Member
 
Join Date: Nov 2007
Posts: 111
Rep Power: 0
bugger is on a distinguished road
Default
Thanks tim. It worked. I simply imported the enumeration using public modifier.
Keep posting mate.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling constructor of parent class from a constructor Java Tip Java Tips 0 12-19-2007 10:10 AM
Calling constructor of same class from a constructor Java Tip Java Tips 0 12-19-2007 10:01 AM
Using enum types (with example) JavaForums Java Blogs 0 11-17-2007 03:43 AM
Enum Iteration A.Russell New To Java 1 08-15-2007 01:17 PM
Enum? vgbhagavan Advanced Java 0 06-14-2007 03:02 PM


All times are GMT +2. The time now is 01:31 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org