zoukankan      html  css  js  c++  java
  • Java静态导入

    例子1:

     1 package cn.itcast.day1;
     2 
     3 public class StaticImport {
     4     public static void main(String[] args)
     5     {
     6         int x = 1;
     7         System.out.println("Hello world!");
     8         System.out.println(Math.max(3, 4));
     9         System.out.println(Math.abs(3 - 23));
    10     }
    11 }

    这里如果调用每个类的静态函数,则需要写上类名进行调用。

     例子2:

     1 package cn.itcast.day1;
     2 
     3 import static java.lang.Math.max;
     4 import static java.lang.Math.abs;
     5 
     6 public class StaticImport {
     7     public static void main(String[] args)
     8     {
     9         int x = 1;
    10         System.out.println("Hello world!");
    11         System.out.println(max(3, 4));
    12         System.out.println(abs(3 - 23));
    13     }
    14 }

    进行了静态导入之后,不需要写上类名即可使用其静态函数了。

    例子3:

    package cn.itcast.day1;
    
    import static java.lang.Math.*;
    
    public class StaticImport {
        public static void main(String[] args)
        {
            int x = 1;
            System.out.println("Hello world!");
            System.out.println(max(3, 4));
            System.out.println(abs(3 - 23));
        }
    }

    静态导入了类Math所有的静态函数。

  • 相关阅读:
    JavaScript高级第01天笔记
    JavaScript基础第06天笔记
    JavaScript基础第05天笔记
    JavaScript基础第04天笔记
    JavaScript基础第03天笔记
    JavaScript基础第02天笔记
    JavaScript基础第01天笔记
    03-CSS文字文本样式
    CSS第二天笔记
    浮动
  • 原文地址:https://www.cnblogs.com/Robotke1/p/3100125.html
Copyright © 2011-2022 走看看