Results 1 to 3 of 3
  1. #1
    camel is offline Member
    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Default static constuctor calls?!

    Hello!

    noob question but here I go!

    when calling a static class for the second time does it use the constructor again or does it skip that?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,017
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by camel View Post
    Hello!

    noob question but here I go!

    when calling a static class for the second time does it use the constructor again or does it skip that?
    You don't 'call a class', you call (static) methods or constructors in a class or objects thereof. If you're talking about initialization code, yes, that code is only called once per class (static initialization) or per object (object initialization code).

    kind regards,

    Jos
    I have the stamina of a seal; I lie on the beach instead of running on it.

  3. #3
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    5

    Default

    To clarify static initialisation is:

    When a static variable is declared and assigned a value at declaration.

    And

    Java Code:
    static
    {
         //static initialisation code (nothing else than just static in the head)
    }

    It is only run once (unless you unload the class, which you can do with jars).





    A static class is a class declared within another class with a static modifier.
    They behave exactly like outer classes.
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

Similar Threads

  1. Replies: 7
    Last Post: 09-24-2010, 05:09 AM
  2. Replies: 4
    Last Post: 05-12-2010, 11:05 AM
  3. Replies: 3
    Last Post: 02-11-2010, 10:59 AM
  4. Replies: 1
    Last Post: 08-07-2007, 05:05 AM
  5. Replies: 1
    Last Post: 08-01-2007, 09:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •