Defining the constants:  'public static final' variables are constant. | 
| The naming convention for static final variables is to have them in upper case and separate two words with an underscore.  For example: | 
         |        static final int NUMBER_OF_MONTHS = 12; static final float PI = (float) 22 / 7;
  |         
  | 
| If you want to make a static final variable accessible from outside the class, you can make it public too: | 
         |        public static final int NUMBER_OF_MONTHS = 12; public static final float PI = (float) 22 / 7;
  
 - Using the final keyword to declare a variable.
 - The final keyword specifies that the value of a variable is final and cannot be changed.
 - It is a convention in Java to write constants in uppercase letters.
 - Sometimes we have to use enums instead of these simple constants for better readability.
 
   |  
  | 
No comments:
Post a Comment