每個類物件都是使用相同的 new 關鍵字建立的,因此它必須包含有關它必須為其建立物件的類的資訊。出於這個原因,建構函式名稱應與類名相同。示例class MyConstructor{ public MyConstructor() { System.out.println("建構函式名稱應與類名相同"); } public static void main(String args[]){ MyConstructor mc = new MyConstructor(); } }在上面的程式中,建構函式名稱應與類名相同 (MyConstructor)。輸出建構函式名稱應與類名相同