导入 static 修饰的包

一 static关键字,可以修饰变量  方法  代码块 ,  静态内部类。  还可以用来修饰 需要导入的包

准备工作

package zhouxufeng;

public class Text1 {
    
    static  int  num = 5;
    
    public  static  void show(){
        System.out.println("展示方法show,import导入方式,需要用类名来调用");
    }

    public static void show2(){
        System.out.println("使用 static 导入后,可以直接调用方法");
    }
    
    public void show3(){
        System.out.println(" 我是导入包的,非静态方法");
    }
}

二  测试效果

package zhouxufeng;

// 加上一个  *   号, 表示获得这个类中所有的静态方法
import static zhouxufeng.Text1.*;

import java.awt.print.Printable;

/*
 * 演示  static   导入包的作用
 * 
 * 
 * 场景
 *         需要频繁用到某个类中的静态方法
 *         
 * 
 */
import zhouxufeng.Text1;

public class StaticDemo {
    public static void main(String[] args) {
        //直接调用静态方法   只能是静态方法
        show();
        show2();        
        
        Text1 text1 = new Text1();
        text1.show3();
    }
    

}

原文地址:https://www.cnblogs.com/ZXF6/p/14118983.html