как застааить работать toString?
package com.javarush.task.task07.task0724;
/*
Семейная перепись
*/
public class Solution {
public static void main(String[] args) {
// напишите тут ваш код
Human grandfather = new Human("Вася", true, 56);
Human grandfather2 = new Human("Юрий",true, 58);
Human grandmother = new Human("Валя", false, 56);
Human grandmother2 = new Human("Юля",false, 58);
Human mother = new Human("Мария", false, 23, grandfather, grandmother);
Human father = new Human("Юрий",true, 38,grandfather, grandmother );
Human children = new Human("Сергей",true, 10, father , mother);
Human children2 = new Human("Аня",false, 13, father , mother);
Human children3 = new Human("Вика",false, 10, father , mother);
toString();
}
public static class Human {
// напишите тут ваш код
public String name;
public boolean sex = true;
public int age;
Human father;
Human mother;
public Human(String n,boolean s, int a){
name = n;
sex = s;
age = a;
}
public Human(String n,boolean s, int a, Human father, Human mother){
name = n;
sex = s;
age = a;
}
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;
}
}
}