my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Forward Referencing... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Forward Referencing..." Watch "Forward Referencing..." New topic
Author

Forward Referencing...

Sandya Bhaskara
Ranch Hand

Joined: Aug 20, 2004
Posts: 73


the above code doesnt compile..an illegal forward reference error is given at line1 by the compiler..

if we make the 1st line as private int i=this.j(though it assigns a value of 0 to i); the code compiles!

or

make 2nd line private static int j=10..here too the code compiles fine(this part i understood..the static variables will be initialized before instance variables..so compiler will have no pblm in assigning i the value of j..but why didnt it assign i ,a value of 0 when i=j was given?why is it not legal?)...


Sandy<br />SCJP1.4 SCWCD1.4<br />SCBCD(preparing)
Doyle Matt
Ranch Hand

Joined: Jul 05, 2004
Posts: 76
I'm not sure about this.j but static variables are created and initialized first before any instance variables. Here's how it goes

First: static blocks
Second: static variables
Third/Fourth: instance blocks or instance variables (not sure what goes in first)


SCJP 1.4
 
wood burning stoves
 
subject: Forward Referencing...
 
Similar Threads
Forward reference
variables & values
forward refrerences
about forward refrencing
Forward referencing