静态变量, 静态方法
public class Student{
private static int age;
private double score;
public Static void main(String[] args){
Student s1 = new Student();
System.out.println(Student.age);
System.out.println(Student.score);
System.out.println(s1.age);
System.out.println(s1.score);
go();
run();
}
public static void go(){
}
public void run(){
}
}
静态代码块
public class Person{
{
System.out.println("匿名代码块");
}
static {
System.out.println("静态代码块");
}
public Person() {
System.out.println("构造方法");
}
public static void main(String[] args){
Person person1 = new Person();
System.out.println("==========");
Person person2 = new Person();
}
}
静态导入包
import static java.lang.Math.random;
import static java.lang.Math.PI;
public class Test {
public static void main(String[] args) {
System.out.println(Math.random());
System.out.println(PI);
}
}