static用法:

  1. 静态变量;
  2. 静态方法;
  3. 静态代码块;
  4. 静态内部类;
  5. 静态导包。

1、静态变量:

private static int a = 0

2、静态方法:

public static void main( String[] args )
    {

        System.out.println( "Hello World!" );
    }

3、静态代码块:

static{
        System.out.println( "Hello World!" );
    }

4、静态内部类:

static class StaticClass{
        public void test(){
            System.out.println( "Hello World!" );
        }
    }

5、静态导包:

import static java.lang.Math.*;
/**
 * 静态导包
 *
 */
public class App {
    public static void main( String[] args ){
        System.out.println( "Hello World!" + Math.round(66.6));//传统做法
        System.out.println( "Hello World!" + round(66.6));
    }
}

 

相关文章:

  • 2022-01-07
猜你喜欢
  • 2022-01-17
  • 2021-09-29
  • 2021-06-28
  • 2021-07-09
  • 2022-12-23
  • 2021-12-25
  • 2021-10-15
相关资源
相似解决方案