「Java」final修飾子、public(protected)修飾子を使うサンプル
構文
final public static 変数名
final protected static 変数名
final private static 変数名
Javaコード
package com.arkgame.study; public class FinalParaDemo { final public static String strA = "111"; final protected static String strB = "222"; final private static String strC = "333"; public static void main(String[] args) { System.out.println("main method " + strA); System.out.println("main method " + strB); System.out.println("main method " + strC); funcA(); } private static void funcA() { System.out.println("private method " + strA); System.out.println("private method" + strB); System.out.println("private method:" + strC); } }
実行結果
main method 111
main method 222
main method 333
private method 111
private method222
private method:333