static修饰属性
例如:
public static int sta=0;
static修饰方法
例如:
public static void printfMethod(){
}
static代码块
static {
}
static导入包
import static java.lang.System.out;
示例代码
import static java.lang.System.out;//静态导包
public class HelloStatic {
public static int a=10;//静态属性
public static void method(){//静态方法
// System.out.println("this is static method");//没有静态导入之前
out.println("this is static method");//静态导入之后
}
static {//静态块
// System.out.println("this is block of static and static a="+a);//没有静态导入之前
out.println("this is block of static and static a="+a);//静态导入之后
}
public static void main(String[] args) {//静态方法
HelloStatic.method();
}
}
输出结果
this is block of static and static a=10
this is static method