• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

When the enum constructor get called up?

 
Ranch Hand
Posts: 35
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I created a constructor inside an enum, just curious to know that how actually it is working?

I just initialized the Computer c = Computer.PERSONAL and constructor is getting invoked two times.
No matter, now many instances i should create apart from compObj, but the constructor is getting invoked 2 times only.

Can any body help me on this logic, how its working?
 
Enthuware Software Support
Posts: 4810
52
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Replace your sout with System.out.println("Constructor invoked "+name()); and then check out http://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html That should help you understand what is going on.
 
Hitesh Kumar C
Ranch Hand
Posts: 35
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Anilprem wrote:Replace your sout with System.out.println("Constructor invoked "+name()); and then check out http://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html That should help you understand what is going on.



Thanks for the suggestion.

Got to know that for each enum the constructor is getting called up.

Confusion is over.

Thanks again.
 
Watchya got in that poodle gun? Anything for me? Or this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic