浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Java Tips - How do I declare a constant in Java

How do I declare a constant in Java
E-mail
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;

}

 


posted on 2012-05-30 15:04  lexus  阅读(241)  评论(0编辑  收藏  举报