????Static???????????????
?????????2??????????? static ????????:
????1. ????
????2. ???????(??????????ξ??????)
????3. ????
????4. ???(??????)
????5. ??(????????????е??? ??????????)
????6. jdk 1.5 ??????????????
???????static ???ε???????? ????????????????????????????????????????????????????????????new???????????????????洢?????????????????????á??????????????????static?????ζ?????????????????????????????????κζ??????????????????????????????????????????????????????????????????Java?????????????????????????????????????????????????static??????????????κζ?????????????????????κζ???
????1. static ????????:
????static{} ?????ж?????????????????????????JVM?????????????????д????飬??????????Ρ?
????2. static ????:
????static ?????????????????ж??????????????????洢???JVM????????????????????????????????????????????????????????static????????????(????.??????)???????????????????????static???????????Щ??????????????????????????????
??????????????????static???????????????????????????????????????????static???????static???Ρ?
???????????????????????????static ?????е????????????÷?????????¥?????????????????????????
public class Person {
????static int[] arr = new int[3];
????public static void main(String[] args){
????Person per1 = new Person();
????Person per2 = new Person();
????Person per3 = new Person();
????System.out.println("----?????-----");
????System.out.print("per1-->");
????per1.show();
????System.out.print("per2-->");
????per2.show();
????System.out.print("per3-->");
????per3.show();
????//???????????????
Person.arr[2]=10;//?????????????
????per1.arr[0]=1;//????????????
????System.out.println("----??????-----");
????System.out.print("per1-->");
????per1.show();
????System.out.print("per2-->");
????per2.show();
????System.out.print("per3-->");
????per3.show();
????}
????//????????????????????????
????public void show(){
????for(int i=0; i
????System.out.print(arr[i] + "t");
????}
????System.out.println("");
????}
????}Output??
????----?????-----
????per1-->0t0t0t
????per2-->0t0t0t
????per3-->0t0t0t
????----??????-----
????per1-->1t0t10t
????per2-->1t0t10t
????per3-->1t0t10t
???????????????????????static???ε????????(??????????)??????????????????????????????????????????????????????????磺“????”+“ . ”+“????”(); ???徲????????????徲??????????
????public class StaticTest2 {
????static void method(){ ("??????????"); }
????}
???????????÷?????StaticTest2 st = new StaticTest2(); ???method??static???ε?(???????)??????????????????StaticTest2.()??
????3. static????:
????static???????static??????????????: static??????????????????????static????????????????????????÷?static??????????????????????????????????????????????????????????????÷????????