「Java」static final修飾子で定数を定義するサンプル
書式
class class名 {
static final 変数の型 変数名 = 値;
}
Javaコード
package com.arkgame.study; class KdfExample { // static final変数の定義 string、int、char、long、double、float static final String cftA = "tokyo"; static final int cftB = 200; static final char cftC = 'K'; static final long cftD = 49433204432234523L; static final double cftE = 6.7; static final float cftF = 3.4F; } public class StaticParamterDemo { public static final void main(String[] args) { System.out.println("実行結果"); // string System.out.println("stringの値:" + KdfExample.cftA); // int System.out.println("intの値:" + KdfExample.cftB); // char System.out.println("charの値:" + KdfExample.cftC); // long System.out.println("longの値:" + KdfExample.cftD); // double System.out.println("doubleの値:" + KdfExample.cftE); // float System.out.println("floatの値:" + KdfExample.cftF); } }
実行結果
stringの値:tokyo
intの値:200
charの値:K
longの値:49433204432234523
doubleの値:6.7
floatの値:3.4