Accessing a static variable via an object reference in Java

前端 未结 6 1423
耶瑟儿~
耶瑟儿~ 2020-11-29 11:26

Why can we access a static variable via an object reference in Java, like the code below?

public class Static {
    private static String x = \"Static variab         


        
6条回答
  •  情话喂你
    2020-11-29 11:52

    static variables are otherwise called as class variables, because they are available to each object of that class.

    As member is an object of the class Static, so you can access all static as wll as non static variables of Static class through member object.

提交回复
热议问题