Java House的構造函數可以定義如下:
public class JavaHouse {
private String name;
private String location;
private int numberOfEmployees;
public JavaHouse(String name, String location, int numberOfEmployees) {
this.name = name;
this.location = location;
this.numberOfEmployees = numberOfEmployees;
}
}
在上面的代碼中,JavaHouse類有一個構造函數,用來初始化JavaHouse對象的屬性:name, location和numberOfEmployees。構造函數的參數分別是name, location和numberOfEmployees,通過調用構造函數時傳入這些參數來初始化JavaHouse對象的屬性。