Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding final

 
RatnaSekhar Kamireddy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,
there is a line in scjp 5 text book(2 minutes drill)
"final reference variables must be initialized before the constructor completes"

whats the actual meaning of this
please explain this in detail
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In above code comment and uncomment line 4 and see result.
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, the final variable has to be initialized before any constructor completes.
The following will not compile due to the sierra-line. If instantiated with a string as argument, variable i wouldn't get a value. 0€.

Yours,
Bu.
 
RatnaSekhar Kamireddy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks i got it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic