my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Enumeration. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Enumeration." Watch "Enumeration." New topic
Author

Enumeration.

babai bhaumik
Greenhorn

Joined: May 12, 2007
Posts: 18
I am trying to write a code on enumeration with constructor but it is giving error.
// practice enumarations along with constructors.

enum ek
{
ff(ff),aa(aa),bb(bb),cc(cc),dd(dd),ss();
ek(String ls)
{
System.out.println("The current enum is "+ ls);
}
ek()
{
System.out.println("The value is " + "arbit");
}
}

public class enumB // here I am trying to call the
{
public static void main(String a[])
{
ek e;
e = ek.aa(aa);
//ek();
}
}

Now this is giving enormous error(I am bit ashamed while saying so).

But I have tried to do the same code with a bit change now it is working!
// practice enumarations along with constructors.

enum ek
{
aa;
}

public class enumB
{
public static void main(String a[])
{
ek e;
e = ek.aa;
if(e == ek.aa) // make a small note when to use
{
System.out.println("It is working");
}
//ek();
}
}
The main issue is with the constructors. I am unable to use the constructors properly. Please suggest.

**
You might face some problem while reading the code, due to wrong indentation. I am trying to indent the code. While editing it is showing the proper indentation. But in view it is not.

[ May 25, 2007: Message edited by: babai bhaumik ]

[ May 25, 2007: Message edited by: babai bhaumik ]
[ May 25, 2007: Message edited by: babai bhaumik ]

Be bold.
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332
You can't create new enums at run-time.

little bit modified your version:
babai bhaumik
Greenhorn

Joined: May 12, 2007
Posts: 18
Hi John,
Thanks for the reply.
I have done following changes in the program.


I was incorrectky mentioning the constructor parameters (in this case String), I was using String without "".
Adding that solved the problem.
Thanks a lot agin.
 
jQuery in Action, 2nd edition
 
subject: Enumeration.
 
Similar Threads
Map Problem
Abstract class..
static methods and NULL
generic question
String split