class Person {
public String firstName;
public String middleName;
public String lastName;
public int age;
// コンストラクタの定義
Person(String firstName, String lastName, int age) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
}
// コンストラクタのオーバーロード
Person(String firstName, String middleName, String lastName, int age) {
// 他のコンストラクタを呼び出し
this(firstName, lastName, age);
this.middleName = middleName;
}
public void printData() {
System.out.println("Hello, " + this.fullName());
System.out.println("AGE: " + this.age);
}
public String fullName() {
if (this.middleName == null) {
return this.firstName + " " + this.lastName;
} else {
return this.firstName + " " + this.middleName + " " + this.lastName;
}
}
}
class Main {
public static void main(String[] args) {
Person person1 = new Person("John", "Marwood", "Cleese", 78);
person1.printData();
Person person2 = new Person("Eric", "Idle", 75);
person2.printData();
}
}