java 面向对象 --static

java 面向对象 --static

package charpter5.Demo09;
//static
public class Student {
    private static  int age;  //静态的变量
    private double  score;    //非静态的变量

    public static void main(String[] args) {
        Student s1 = new Student();
        System.out.println(s1.age);
        System.out.println(Student.age);
        System.out.println(s1.score);
       // System.out.println(Student.score);   不可调用

    }
}

静态导入包

package charpter5.Demo09;

//静态导入包
import static java.lang.Math.random;

public class Static {
    public static void main(String[] args) {
        System.out.println(random());
    }
}
posted @ 2022-09-27 13:08  林每天都要努力  阅读(19)  评论(0)    收藏  举报