/** 聽* 聽* @author livahu 聽* Created on 2006騫?鏈?鏃? 涓嬪崍17:00 聽*/ class FirstClass { 聽聽聽 FirstClass(int i) { 聽聽聽聽聽聽聽 System.out.println("FirstClass(" + i + ")"); 聽聽聽 } 聽聽聽 聽聽聽 void useMethod(int k) { 聽聽聽聽聽聽聽 System.out.println("useMethod(" + k + ")"); 聽聽聽 } }
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!