嘗試一下:
public class Try { final static int a = 1; public Try() { System.out.print("構造方法"); } public static void pt() { System.out.print("靜態方法"); } public static void main(String[] args) { pt(); System.out.print(a); } }
執行結果:
說明在調用一個類的靜態方法時並沒有執行這個類的構造方法,而這個類其中的靜態常量是可以直接調用的。