Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Enumeration.

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't create new enums at run-time.

little bit modified your version:
 
babai bhaumik
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic