Помогите вывести на экран, используя метод toString().
У меня выводит ошибку использования метода в статическом режиме.
package com.javarush.task.task08.task0824;
/*
Собираем семейство
*/
import java.util.*;
import java.io.*;
public class Solution {
public static void main(String[] args) {
ArrayList<Human> childrens = new ArrayList<>();
Human children1 = new Human("Children1", true, 15, null);
childrens.add(children1);
Human children2 = new Human("Children2", false, 12, null);
childrens.add(children2);
Human children3 = new Human("Children3", true, 8, null);
childrens.add(children3);
Human father = new Human("Father", true, childrens, 38);
Human mather = new Human("Mather", false, childrens, 35);
Human ded1 = new Human("Ded1", true, 85, father);
Human bab1 = new Human("Bab1", false, 83, father);
Human ded2 = new Human("Ded2", true, 75, mather);
Human bab2 = new Human("Bab2", false, 76, mather);
System.out.println(Human.toString());
}
public static class Human {
String name = null;
boolean sex = false;
int age = 0;
ArrayList<Human> childrens = null;
Human children = null;
public Human(String name, boolean sex, int age, Human children) {
this.name = name;
this.sex = sex;
this.age = age;
this.children = children;
}
public Human(String name, boolean sex, ArrayList<Human> childrens, int age) {
this.name = name;
this.sex = sex;
this.age = age;
this.childrens = childrens;
}
public String toString() {
String text = "";
text += "Имя: " + this.name;
text += ", пол: " + (this.sex ? "мужской" : "женский");
text += ", возраст: " + this.age;
int childCount = this.childrens.size();
if (childCount > 0) {
text += ", дети: " + this.childrens.get(0).name;
for (int i = 1; i < childCount; i++) {
Human children = this.childrens.get(i);
text += ", " + children.name;
}
}
return text;
}
}
}