如何在 Java 中編寫常量名稱?


在編寫常量名稱時建議

  • 使用大寫字母。
  • 如果常量包含多個單詞,則應使用下劃線 (_) 分隔。

示例

即時演示

public class ConstantsTest {
   public static final int MIN_VALUE = 22;
   public static final int MAX_VALUE = 222;
   public static void main(String args[]) {
      System.out.println("Value of the constant MIN_VALUE: "+MIN_VALUE);
      System.out.println("Value of the constant MAX_VALUE: "+MAX_VALUE);
   }
}

輸出

Value of the constant MIN_VALUE: 22
Value of the constant MAX_VALUE: 222

更新時間:2019 年 7 月 30 日

623 次瀏覽

開始你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.