静态方法,静态变量
public class Studnet {
private static int age;
private double score;
public void run(){
}
public static void go(){
}
public static void main(String[] args) {
go();
int i = age;
Studnet studnet = new Studnet();
studnet.run();
double j = studnet.score;
}
}
匿名代码块,静态代码块和构造方法
public class Person {
{
System.out.println("匿名代码块");
}
static{
System.out.println("静态代码块");
}
public Person() {
System.out.println("构造方法");
}
public static void main(String[] args) {
Person person = new Person();
System.out.println("---------------------------");
Person person1 = new Person();
}
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/443ced05f9110639bc4d0885773db9f9.png)
静态导入方法
import static java.lang.Math.random;
public class Test {
public static void main(String[] args) {
System.out.println(random());
}
}