1. 程式人生 > >static面試總結

static面試總結

變量 str int 內部 內部類 bsp nbsp oid span

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

static面試總結