首页 > 编程语言 > 详细

JAVASE static

时间:2021-07-20 23:17:04      阅读:17      评论:0      收藏:0      [点我收藏+]

JAVASE的static

javase的static是和类一块初始化的。

package STATIC静态;

public class test {
    static int age;
    int score;

    public static void main(String[] args) {
        test.age=100;//可以直接用类名调用静态变量age
        test t1=new test();
        t1.score=100;
        System.out.println(t1.age);
    }
}
package STATIC静态;

public class person {

    {
        System.out.println("匿名代码块");
    }
    //静态代码块只执行一次
    static {
        System.out.println("静态代码块");
    }

    person() {
        System.out.println("无参构造器");
    }

    public static void main(String[] args) {
        person p1 = new person();
        System.out.println("=========================");
        person p2=new person();
    }
}
package STATIC静态;
//静态import导入包
import static java.lang.Math.random;
public class student {
    public static void main(String[] args) {
        System.out.println(random());
    }
}

 

JAVASE static

原文:https://www.cnblogs.com/Sum-muji/p/15036639.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!