wood burning stoves 2.0*
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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 :http://www.javabeat.net/javabeat/scjp5/mocks/scjp_5_0_mock_questions_enums_part2.php
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: 18505

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: 1753

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!
Consider Paul's rocket mass heater.
subject: enum constructor help
Similar Threads
Constructor issues with creating a new checking account object.
Enum's doubt from Java Beat
Doubt about Enum .
Class Diagram -Association & Inheritance