Results 1 to 4 of 4
- 05-27-2008, 12:39 AM #1
[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
- 05-27-2008, 03:06 AM #2
yah, you may initialize them in a static block,
or in global (outside the methods)freedom exists in the world of ideas
- 05-27-2008, 04:42 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Static initialization block is much better I think. Use of that, gives a much clear to the code.
- 05-27-2008, 02:21 PM #4
Similar Threads
-
non-static member can not be referenced from a static context
By christina in forum New To JavaReplies: 3Last Post: 03-20-2009, 12:35 AM -
Non-Static method in static context error
By wizmang in forum New To JavaReplies: 4Last Post: 04-24-2008, 08:51 AM -
Explicit static initialization with the static clause
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 11:07 PM -
Error: Non-static method append(char) cannot be referenced from a static context
By paul in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 05:05 AM -
Error: non-static variable height cannot be referenced from a static context at line
By fernando in forum AWT / SwingReplies: 1Last Post: 08-01-2007, 09:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks