锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
涓嶈繃鏈夌偣鏃犳硶鎺ュ彈,鍙兘鎴戞病鏈夐偅澶╄祴
灝辨槸hostman鐨勪唬鐮侀鏍間竴鑸兘鏄厛鍐檓ethod,鐒跺悗鎵嶆槸field.
璁╀漢寰堟槸鍙樻壄.
鎴戠敤ide瑙夊緱涓嶆槸寰堥『鐣?
鏈変簨浜?br />鍏堝啓鍒拌繖鍚?br />
class SecondClass {
聽聽聽 static FirstClass fc1 = new FirstClass(1);
聽聽聽 FirstClass fc3 = new FirstClass(3);
聽聽聽 static {
聽聽聽聽聽聽聽 FirstClass fc2 = new FirstClass(2);
聽聽聽 }
聽聽聽
聽聽聽 {
聽聽聽聽聽聽聽 System.out.println("SecondClass's block, this block is not static block.");
聽聽聽 }
聽聽聽
聽聽聽 SecondClass() {
聽聽聽聽聽聽聽 System.out.println("SecondClass()");
聽聽聽 }
聽聽聽
聽聽聽 FirstClass fc4 = new FirstClass(4);
}
public class InitiationDemo {
聽聽聽 SecondClass sc1 = new SecondClass();
聽聽聽
聽聽聽 {
聽聽聽聽聽聽聽 System.out.println("Hello Java World!");
聽聽聽 }
聽聽聽
聽聽聽 public static void main(String[] args) {
聽聽聽聽聽聽聽 System.out.println("Inside main()");
聽聽聽聽聽聽聽 SecondClass.fc1.useMethod(100);
聽聽聽聽聽聽聽 InitiationDemo idObj = new InitiationDemo();
聽聽聽 }
聽聽聽
聽聽聽 static SecondClass sc2 = new SecondClass();
}
榪愯緇撴灉:
FirstClass(1)
FirstClass(2)
FirstClass(3)
SecondClass's block, this block is not static block.
FirstClass(4)
SecondClass()
Inside main()
useMethod(100)
FirstClass(3)
SecondClass's block, this block is not static block.
FirstClass(4)
SecondClass()
Hello Java World!