Can non-static methods modify static variables

前端 未结 9 2080
猫巷女王i
猫巷女王i 2020-11-29 01:53

I am wondering how a non static method can modify a static variable. I know that static methods can only access other static methods and static variables. However, is the ot

9条回答
  •  醉梦人生
    2020-11-29 02:08

    Look at it this way. A static variable can be accessed in many ways. One of the most common is to precede the var name with the class name, since static vars are per class. Since you refer to this variable in the same class, you are exempt from having to precede it with the class name. It does not matter where you call the static variable. Also this is a private static var not accessible by any other class.

提交回复
热议问题