| Author |
Doubt about Enum .
|
Manishk Rai
Greenhorn
Joined: Jul 06, 2007
Posts: 21
|
|
The following piece of code prints the output It is a account type It is a account type SAVING I think the correct o/p is It is a account type SAVING Because it calls the constructor ( private) implicitly . But why one exta "It is a account type" . Thanks
|
 |
Sergey Petunin
Ranch Hand
Joined: Dec 16, 2007
Posts: 44
|
|
When you first use the enum type, every single enum constant is initialized, that is, the constructor for this constant is called. So when you try to print an AccountType constant in your main method, the constructor is called once for every initialization constant. But after that it will never be called again, no matter how much you use the constants. So if we change the main method like this: , the output is going to be:
|
 |
sree visu
Ranch Hand
Joined: Jul 05, 2007
Posts: 133
|
|
|
a very nice answer .hats off...
|
Regards<br />Sree Visu<br />SCJP 5.0, SCWCD 5.0, SCJD(Preparing B&S 2.2.2)
|
 |
Manishk Rai
Greenhorn
Joined: Jul 06, 2007
Posts: 21
|
|
|
Thanks Serge
|
 |
 |
|
|
subject: Doubt about Enum .
|
|
|