• Post Reply Bookmark Topic Watch Topic
  • New Topic

final variable  RSS feed

 
cybel sheriden
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
page 130 of k&b says " final reference variable must be initialized before the constructor completes"

i thought the above statement is true for final instance variable.
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is "k&b"?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37465
539
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cybel,
A primitive (like an int) has a default value. So if you don't explitly initialize it, there is still a value.

James k&b refers to Head First Java by Kathy Sierra & Bert Bates.
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cybel,

Your statement is true for instance variables. A static final variable must be initialized inline or by a static initializer block.

Jeanne,
A final variable cannot assume a "default" value. And, thanks for the clarification. I've seen that K&B around this site a lot. Sounds like a good book.
 
cybel sheriden
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. "A static final variable must be initialized inline or by a static initializer block."

hi

what is static initializer block....i haven't come across it.....
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by James Carman:
I've seen that K&B around this site a lot. Sounds like a good book.

That's probably because the authors are co-founders of this site. We occassionally even see posts from them. In fact, iirc, they will be in beginner forum promoting their book in a week or two.

Layne
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!