aspose file tools*
The moose likes Beginning Java and the fly likes final instance variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "final instance variables" Watch "final instance variables" New topic
Author

final instance variables

sri yadagini
Greenhorn

Joined: Jan 06, 2006
Posts: 6
If a final instance variable is not initialized, does it take the default value?
I am getting a compiler error when i am trying to execute the following code:




What i thought is-- the variable i will be printed as '0', the default value for int.
Aleksander Zielinski
Ranch Hand

Joined: Nov 11, 2005
Posts: 127
Final variable must be initialized when being declared or in the constructor.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Aleksander Zielinski:
Final variable must be initialized when being declared or in the constructor.

Or, in other words, by the time the constructor exits.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

See the JLS �8.3.1.2


Junilu - [How to Ask Questions] [How to Answer Questions]
sri yadagini
Greenhorn

Joined: Jan 06, 2006
Posts: 6
I appreciate for all the replies.I understood the concept.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: final instance variables
 
Similar Threads
final variables (instance and local)
Initializing final memeber variable
Re : final keyword with objects
SCJP 1.5 Study Group.
Please explain final