Results 1 to 4 of 4
  1. #1
    JT4NK3D's Avatar
    JT4NK3D is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Question [SOLVED] static block or constructor?

    In a class i have all my fields declared at the start, including 2 static final fields. The static fields are the only ones i can initialize when an instance of this class is created/at the start of the program. So should I initialize them in the constructor, or leave the constructor empty and instead, immediately following the declaring of the fields, use a static block and initialize them there?
    thanks in advance.:D

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    yah, you may initialize them in a static block,

    or in global (outside the methods)
    freedom exists in the world of ideas

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Static initialization block is much better I think. Use of that, gives a much clear to the code.

  4. #4
    JT4NK3D's Avatar
    JT4NK3D is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

Similar Threads

  1. Replies: 3
    Last Post: 03-20-2009, 01:35 AM
  2. Non-Static method in static context error
    By wizmang in forum New To Java
    Replies: 4
    Last Post: 04-24-2008, 09:51 AM
  3. Replies: 0
    Last Post: 04-17-2008, 12:07 AM
  4. Replies: 1
    Last Post: 08-07-2007, 06:05 AM
  5. Replies: 1
    Last Post: 08-01-2007, 10: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
  •