File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes enum constructor help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "enum constructor help" Watch "enum constructor help" New topic

enum constructor help

Sun Craven

Joined: Mar 13, 2008
Posts: 27
given the following test
enum AccountType {
private AccountType() {
System.out.println("It is a account type");
class EnumOne {
public static void main(String[] args) {
the answer is :Compiles fine and output is prints "It is a account type" thrice followed by "FIXED
quto source :
So i confused by when the enum constructor run..
sun jiuzhen
[ March 13, 2008: Message edited by: sun jiuzhen ]
Henry Wong

Joined: Sep 28, 2004
Posts: 20521

Source " Free online mock test"

Please Quote Your Sources. We need a recognizable source, or a link.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jelle Klap

Joined: Mar 10, 2008
Posts: 1951

An enum type's constructor will run once for every constant it defines when the enum type is first used. For instance:

Try playing around with it.

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Padmanabh Sahasrabudhe
Ranch Hand

Joined: Mar 04, 2008
Posts: 53
Thanks Jelle. It answers. I just added One more SOP and the output confirmed me that.

C:\>java EnumExample
Invoked for type: A
Invoked for type: B
Milton Ochoa
Ranch Hand

Joined: Oct 23, 2007
Posts: 336

Padmanabh, sorry by contactin in this way, but you askme something via email, but Im unavailable to contact you via email or private mensaje!.
so.... sorry for no give you a answer!
I agree. Here's the link:
subject: enum constructor help
It's not a secret anymore!