Scope of static variable and methods in Java

后端 未结 6 1386
自闭症患者
自闭症患者 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:11

    Static variables are "per class". So it doesn't matter if your static variable in this class has same name/type as some other.

    It's global in the sense that no matter how many object of that class you have, if you have them use a static variable, they'll all be using one var.

提交回复
热议问题