static面試總結
阿新 • • 發佈:2018-11-13
變量 str int 內部 內部類 bsp nbsp oid span
static用法:
- 靜態變量;
- 靜態方法;
- 靜態代碼塊;
- 靜態內部類;
- 靜態導包。
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、靜態內部類:
staticclass 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面試總結