Common problems and misunderstandings about Java static

Use misunderstanding

public class Student {
    public static String name = "张三";
    private static int age = 10;
}
public class Main {
    public static void main(String[] args) {
        System.out.println(Student.name);
        System.out.println(Student.age);
    }
}
public class Main {
    static int value = 33;

    public static void main(String[] args) throws Exception {
        new Main().printValue();
    }

    private void printValue() {
        int value = 3;
        System.out.println(this.value);    // 输出 33
    }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>