File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
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://aspose.com/file-tools
 
subject: Restrictions on the use of Fields during Initialization
 
Similar Threads
member assignmnet
static initialization blocks are there in exam?
Initializers...
for loop question
Hurting My Brains