Java Global variable examples
By:Roy.LiuLast updated:2019-08-11
In Java, there is no global keyword, but we can use public static variable to referring a global variable.
For example :
MagicUtils.java
package com.mkyong.example; public class MagicUtils { public static final String NAME = "mkyong"; // global public static final int LUCKY_NUMBER = 7; // global
JavaExample.java
package com.mkyong.example; public class JavaExample { public static void main(String[] args) { System.out.println(MagicUtils.NAME); System.out.println(MagicUtils.LUCKY_NUMBER);
Output
mkyong
References
From:一号门
Previous:Maven PMD example
COMMENTS