「Java」クラスのstatic変数を利用する方法
書式
class class名 {
static 変数の型 method名;
}
Javaコード
package com.arkgame.study;
class CftExample {
// static変数の定義 string、int、char、long、double、float
static String cftA = "tokyo";
static int cftB = 100;
static char cftC = 'U';
static long cftD = 49433204432234523L;
static double cftE = 6.5;
static float cftF = 3.2F;
}
public class StaticParamterDemo {
public static void main(String[] args) {
// string
System.out.println("stringの値:" + CftExample.cftA);
// int
System.out.println("intの値:" + CftExample.cftB);
// char
System.out.println("charの値:" + CftExample.cftC);
// long
System.out.println("longの値:" + CftExample.cftD);
// double
System.out.println("doubleの値:" + CftExample.cftE);
// float
System.out.println("floatの値:" + CftExample.cftF);
}
}
実行結果
stringの値:tokyo
intの値:100
charの値:U
longの値:49433204432234523
doubleの値:6.5
floatの値:3.2