• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Forward Referencing...  RSS feed

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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?)...
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!