Java Tips How do I declare a constant in Java

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;

}


原文地址:https://www.cnblogs.com/lexus/p/2526347.html