Java static关键字
package com.oop.demo07;
public class Student {
private static int age; //静态的变量 多线程!
private double score; //非静态的变量
public void run(){
}
public static void go(){
}
public static void main(String[] args) {
//new Student().run();
Student.go(); //go();
/*Student s1 = new Student();
System.out.println(Student.age);
// System.out.println(Student.score);
System.out.println(s1.age);
System.out.println(s1.score);*/
}
}
package com.oop.demo07;
public class Person {
//2 赋初始值
{
System.out.println("匿名代码块"); //代码块(匿名代码块)
}
//1 只执行一次
static {
System.out.println("静态代码块"); //静态代码块
}
//3
public Person() {
System.out.println("构造方法");
}
public static void main(String[] args) {
Person person = new Person();
System.out.println("=============");
Person person1 = new Person();
}
}
static关键字的四种用法
https://www.cnblogs.com/dolphin0520/p/3799052.html
https://www.cnblogs.com/dolphin0520/p/10651845.html
https://www.cnblogs.com/heimianshusheng/p/5828844.html

浙公网安备 33010602011771号