首页 > 编程笔记

Java static关键字的作用和用法

static 关键字主要有两个作用:
本文将简要介绍一下 Java static 的作用。

1) 可修饰的元素

2) Java static使用说明

static,静态,表示随着类的加载而加载,不会重复加载,执行顺序在 main 方法之前。在 JVM 内存里,static 修饰的变量存在于方法区中。静态导入包比较少见,其语法如下所示:
import static book.Constants.*;  //引入 Constants 下的所有 static 变量

public class StaticImportConstants {

    public static void main(String[] args)
    {
        int start = START;
    }
}
public interface Constants {
   
    int START = 1;
    int END = 2;
}

优秀文章