• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

final reference variables K&B SCJP 6

 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Please examine the code snippet below. I don't understand why K&B say that "reference variables must be initialized before the constructor completes." The code below compiles and runs just fine.

Thanks,

K&B Two Minute Drill Chapter 1 wrote:final variables have the following properties:
final variables cannot be reinitialized once assigned a value.
final reference variables cannot refer to a different object once the object has been assigned to the final variable.
final reference variables must be initialized before the constructor completes.



C:\temp>cat Final.java



C:\temp>vi Final.java

C:\temp>gvim.exe Final.java

C:\temp>javac Final.java

C:\temp>java Final
thisReference says hello
10
 
author & internet detective
Posts: 42135
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That comment means final instance (or static) variables must be initialized before the constructor completes.
 
reply
    Bookmark Topic Watch Topic
  • New Topic