What is the use of a private static variable in Java?

前端 未结 19 2231
灰色年华
灰色年华 2020-12-02 03:47

If a variable is declared as public static varName;, then I can access it from anywhere as ClassName.varName. I am also aware that static members a

19条回答
  •  爱一瞬间的悲伤
    2020-12-02 04:28

    When in a static method you use a variable, the variable have to be static too as an example:

    private static int a=0;  
    public static void testMethod() {  
            a=1;  
    }
    

提交回复
热议问题