• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

final instance variables

 
sri yadagini
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Final variable must be initialized when being declared or in the constructor.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Junilu Lacar
Bartender
Pie
Posts: 7749
61
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the JLS �8.3.1.2
 
sri yadagini
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I appreciate for all the replies.I understood the concept.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic