????Java??????????
???????????? ???????[ 2012/11/8 10:25:54 ] ????????
????????Sub.B?ж?????????????????Sub??????г????????????丸??Parent?????г??????????Parent???????A=2??????B=2??????????????
static class Parent{
<clinit>(){
public static int A=1;
static{
A=2;
}
}
}
static class Sub extends Parent{
<clinit>(){ //jvm??????????÷?????????????????
public static int B=A;
}
}
public static void main(String[] args){
System.out.println(Sub.B);
}
????<clinit>();???????????????????????????????????????ж?????????и??????о??????飬<clinit>()?????????????????ɡ?
?????????????治?????static{}??????????飬????????????????????????????????????????????????????<clinit>()??????????????????????????????<clinit>();??????????????и?????<clinit>();??????????????ж?????????????????????????????
??????????????????????????????????????н???<clinit>()????????
????????jvm?????????<clinit>();???????????????????????????????<?????????????????>??
????????????????????£?
public class DeadLoopClass {
static{
if(true){
System.out.println("??? ["+Thread.currentThread()+"] ????????????????????????");
while(treu){}
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("toplaile");
Runnable run=new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("["+Thread.currentThread()+"] ??????????????");
DeadLoopClass d=new DeadLoopClass();
System.out.println("["+Thread.currentThread()+"] ???????????????????");
}};
new Thread(run).start();
new Thread(run).start();
}
}
?????????棬???е????????????????
??????
???·???
??????????????????
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