variables in enum

+1 Ankit Ojha · January 4, 2016
why the two variable(desc and year) declared as "PRIVATE FINAL STRING" because the program also works while declaring the variables as  "PRIVATE STRING".
Why is FINAL keyword used?

Post a Reply


Oldest  Newest  Rating
0 Darren Reeder · January 4, 2016
I've not used the final keyword before. But youtube brought me to a few videos on it.

When you use FINAL variable, it can only be initialised once. So, if you have a PIRVATE FINAL STRING with the value "hello world", the value will always stay as "hello world" and it cannot be changed. 

Im thinking of it like the variable saying "Whatever the next bit of data thats is given to me is, will be my final value forever".
0 Nicholas Eason · January 4, 2016
The final keyword is used because he doesn't want the Strings to be changed. While final isn't necessary, declaring a constant final is good programming practice.
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator