static关键字详解
package com.oop.demo07; //static 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 com.oop.demo07; public class Person { /* { //代码块(匿名代码块) } static { //静态代码块 } */ //第二个执行 赋初值 { 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(); } }
package com.oop.demo07; //静态导入包 import static java.lang.Math.random; public class Test { public static void main(String[] args) { System.out.println(Math.random()); } }
标签:Day8,System,Person,详解,static,println,public,out From: https://www.cnblogs.com/actadams68/p/16903166.html