aspose file tools
The moose likes Beginning Java and the fly likes Restrictions on the use of Fields during Initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Restrictions on the use of Fields during Initialization" Watch "Restrictions on the use of Fields during Initialization" New topic
Author

Restrictions on the use of Fields during Initialization

Hemant Agarwal
Ranch Hand

Joined: Nov 21, 2005
Posts: 138
compile-time error results from the test program:



whereas the following example compiles without error:




Why is it so?
Stuart Ash
Ranch Hand

Joined: Oct 07, 2005
Posts: 637
Because methods, including constructors, are "after" fields: they are considered separately from the field declarations.
But between two fields, order matters.


ASCII silly question, Get a silly ANSI.
Adam Richards
Ranch Hand

Joined: Nov 03, 2005
Posts: 133
To put it another way: Your first assignment refers to variable j, which hasn't been declared yet, so the compiler doesn't recognize it (j).
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Restrictions on the use of Fields during Initialization
 
Similar Threads
static initialization blocks are there in exam?
Hurting My Brains
member assignmnet
for loop question
Initializers...