Source: http://www.imooc.com/code/1256
The so-called constant, which we can understand as a special variable, whose value is set, is not allowed to change during program Operation .
Syntax:final constant name = value;
Using Constants in your program can improve the maintainability of your code. For example, in project development, we need to specify the user's gender, at this time can be defined as a constant sex, assigned to "male", in the need to specify a user-specific place to call this constant directly, to avoid the user's non-standard assignment caused the program error situation.
Guys, watch out.: Constant names generally use uppercase characters
Task
Little friends, let's define a constant and play it!
In the editor, define two constants that are used to save the gender of the user and to print out
1 Public class helloworld{2 Public Static void Main (string[] args) {3 4 5 6 }7 }
1 Public classhelloworld{2 Public Static voidMain (string[] args) {3 4 Final CharSex_man= ' man ';5 FinalString sex_lady= "Female";6 System.out.println (Sex_man);7 System.out.println (sex_lady);8 }9}
Mu Network-android engineer -2-11 Java constants in the first form