Static
package oop.Dome07;
public class Student {
private static int age;
private double score;
public void run(){
}
public static void go(){
}
public static void main(String[] args) {
Student s1= new Student();
System.out.println(Student.age);
System.out.println(s1.age);
System.out.println(s1.score);
}
}
package oop.Dome07;
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();
}
}
静态代码块
匿名代码块
构造方法
======================
匿名代码块
构造方法
Process finished with exit code 0
package oop.Dome07;
import static java.lang.Math.random;
public class Test {
public static void main(String[] args) {
System.out.println(Math.random());
System.out.println(random());
}
}