Results 1 to 3 of 3
Thread: Constructor with enum
- 01-02-2008, 04:03 PM #1
Senior Member
- Join Date
- Nov 2007
- Posts
- 111
- Rep Power
- 0
Constructor with enum
I have the following class:
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.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; }
- 01-03-2008, 10:40 PM #2
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:
Hope this helped. ;)Java Code:GTent test = new GTent(0, 0, GTent.ttype.RANGE);
Eyes dwelling into the past are blind to what lies in the future. Step carefully.
- 01-04-2008, 11:21 AM #3
Senior Member
- Join Date
- Nov 2007
- Posts
- 111
- Rep Power
- 0
Similar Threads
-
Calling constructor of parent class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:10 AM -
Calling constructor of same class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:01 AM -
Enum Iteration
By A.Russell in forum New To JavaReplies: 1Last Post: 08-15-2007, 12:17 PM -
Enum?
By vgbhagavan in forum Advanced JavaReplies: 0Last Post: 06-14-2007, 02:02 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks