(这是下面两点前提)
public class Student { private static int age; private double score; { System.out.println("匿名代码块"); } static { System.out.println("静态代码块"); } public Student() { System.out.println("构造方法"); } public static void main(String[] args) { Student student = new Student(); Student student1 = new Student(); } }
程序输出
静态代码块 匿名代码块 构造方法 匿名代码块 构造方法
import static java.lang.Math.random; public class HelloWorld { public static void main(String[] args) { System.out.println(random()); } }