Scope of static variable and methods in Java

后端 未结 6 1269
自闭症患者
自闭症患者 2021-01-18 21:38

I have some doubts about usage of static method in Java. I read many places static variables are instance independent so be comes global.

public class ThirdC         


        
6条回答
  •  [愿得一人]
    2021-01-18 22:02

    The value is initialized when the class is loaded. Therefore each time you execute the code, it is initialized to the value "Java" as is defined in the class. The new value is not saved, it is only changed in memory and is "reset" when the code is executed again.

    The term global has nothing to do with the variables persistence, and scope is defined only within the running program.

提交回复
热议问题