您的位置:首页 > 编程语言 > Java开发

Java Tips - How do I declare a constant in Java

2012-05-30 15:04 260 查看
Java Tips - How do I declare a constant in Java

How do I declare a constant in Java


User Rating:









/ 140

PoorBest
Java does not directly support constants. However, a static final variable is effectively a constant.

The static modifier causes the variable to be available without loading an instance of the class where it is defined. The final modifier causes the variable to be unchangeable.

Java constants are normally declared in ALL CAPS. Words in Java constants are normally separated by underscores.

An example of constant declaration in Java is written below:

public class MaxUnits {

public static final int MAX_UNITS = 25;

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: