• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

enum constructor help

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
given the following test
enum AccountType {
SAVING, FIXED, CURRENT;
private AccountType() {
System.out.println("It is a account type");
}
}
class EnumOne {
public static void main(String[] args) {
System.out.println(AccountType.FIXED);
}
}
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..
Thanks
sun jiuzhen
[ March 13, 2008: Message edited by: sun jiuzhen ]
 
author
Posts: 23931
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Source " Free online mock test"



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

Thanks,
Henry
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jelle. It answers. I just added One more SOP and the output confirmed me that.


Output:
C:\>java EnumExample
Invoked for type: A
Invoked for type: B
A
B
A
 
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic