Java??static??????÷????
???????????? ???????[ 2015/12/9 10:50:28 ] ??????????????? ???????????
????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??????????????????????????????????????????????????????????????÷????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11