static面试总结

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));
    }
}

 

posted @ 2018-11-12 22:04  胡金水  阅读(621)  评论(0编辑  收藏  举报