aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes final reference variables K&B SCJP 6 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "final reference variables K&B SCJP 6" Watch "final reference variables K&B SCJP 6" New topic
Author

final reference variables K&B SCJP 6

Harry Henriques
Ranch Hand

Joined: Jun 17, 2009
Posts: 206
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
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30925
    
158

That comment means final instance (or static) variables must be initialized before the constructor completes.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: final reference variables K&B SCJP 6