File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Instance Initializer and Forward Referancing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Instance Initializer and Forward Referancing" Watch "Instance Initializer and Forward Referancing" New topic
Author

Instance Initializer and Forward Referancing

Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
Why is the error coming in Forward Referancing
done in the Instance Initializer used in the nested class


/** Code speaks louder than words */
Arvind Giri
Ranch Hand

Joined: Jun 26, 2005
Posts: 91
dear sivani,
Think this way :
in class A hg and lf are instance variable
however in class B these are local variable.


Regards<br /> <br />Arvind Giri<br />MCA,SCJP 1.4,SCWCD 1.4<br />Looking for SCDJWS
Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
Instance variable vs.local variables - wat are the differences in the rules for forward referencing for them?
Kevin Vicy
Greenhorn

Joined: Aug 21, 2005
Posts: 6
int hg = lf = 90; // declaration for 'hg' not for 'lf'
int lf; // only here 'lf' is declared

this member variables declaration can also be done as follows

int lf;
int hg = lf = 90;

this type of declaration ordering is not an issue with member variables but matters for local variable declaration. Hope this helps!
Arvind Giri
Ranch Hand

Joined: Jun 26, 2005
Posts: 91
dear Shivani,
rules for local variable is "variable must be declared before accessing it" and one can't make a forward reference to local variable.

Hope this helps you
 
wood burning stoves
 
subject: Instance Initializer and Forward Referancing