Application of Java constants
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;
650) this.width=650; "src=" http://img.mukewang.com/53689a880001620703990081.jpg "/>
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
Code:
public class helloworld{
public static void Main (string[] args) {
Final String male= "male";
Final String female= "female";
SYSTEM.OUT.PRINTLN (male);
SYSTEM.OUT.PRINTLN (female);
}
}
Operation Result:
Man
Woman
This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1547646
Java Fundamentals---Application of Java constants (ix)