static的用法实例
package com.lyh.oop1;
public class StaticDemo {
private static int age;
private double score;
public void run(){
}
public static void go(){
}
public static void main(String[] args) {
StaticDemo s1 = new StaticDemo();
System.out.println(StaticDemo.age);
System.out.println(s1.age);
System.out.println(s1.score);
go();
}
}
package com.lyh.oop1;
public class StaticCode {
{
System.out.println("匿名代码块");
}
static{
System.out.println("静态代码块");
}
public StaticCode(){
System.out.println("构造方法");
}
public static void main(String[] args) {
StaticCode person = new StaticCode();
System.out.println("==========");
StaticCode person2 = new StaticCode();
}
}
package com.lyh.oop1;
import static java.lang.Math.random;
import static java.lang.Math.PI;
public class StaticTest {
public static void main(String[] args) {
System.out.println(Math.random());
System.out.println(random());
System.out.println(PI);
}
}