Объясните пожалуйста как работает метот ту стринг для фазер и мазер, как они вызывают его? ничо не понял, а еслиб нужно было для бати 1 метод вызывать а для мамки ту
public class Solution {
public static void main(String[] args) {
Human Grandfater1 = new Human("Иван", true, 60);
Human Grandfather2 = new Human("Петр", true, 65);
Human Grandmother1 = new Human("Антуанетта", false, 57);
Human Grandmother2 = new Human("Елизавета", false, 60);
Human Father = new Human("Александр", true, 40, Grandfater1, Grandmother1);
Human Mother = new Human("Екатерина", false, 38, Grandfather2, Grandmother2);
Human Sun = new Human("Сергей", true, 16, Father, Mother);
Human Daughter1 = new Human("Анна", false, 14, Father, Mother);
Human Daughter2 = new Human("Яна", false, 18, Father, Mother);
System.out.println(Grandfater1);
System.out.println(Grandmother1);
System.out.println(Grandfather2);
System.out.println(Grandmother2);
System.out.println(Father);
System.out.println(Mother);
System.out.println(Sun);
System.out.println(Daughter1);
System.out.println(Daughter2);
}
public static class Human {
String name;
boolean sex;
int age;
Human father;
Human mother;
public Human(String name, boolean sex, int age){
this.name=name;
this.sex=sex;
this.age=age;
}
public Human(String name, boolean sex, int age, Human father, Human mother) {
this.name=name;
this.sex=sex;
this.age=age;
this.father=father;
this.mother=mother;
}
public String toString() {
String text = "";
text += "Имя: " + this.name;
text += ", пол: " + (this.sex ? "мужской" : "женский");
text += ", возраст: " + this.age;
if (this.father != null) {
text += ", отец: " + this.father.name;
}
if (this.mother != null) {
text += ", мать: " + this.mother.name;
}
return text; } } }