Не могу понять почему не компилируется код, сто раз уже все проверил...где ошибка?
public class Solution {
public static void main(String[] args) {
Human child1 = new Human("Anny", false, 10, father, mother);
Human child2 = new Human("Lory", false, 16, father, mother);
Human child3 = new Human("Jeck", true, 14, father, mother);
Human mother = new Human("Mom", false, 45, deda1, baba1);
Human father = new Human("Dad", true, 50, deda2, baba2);
Human baba1 = new Human("Lena", false, 72);
Human baba2 = new Human("Olya", false, 73);
Human deda1 = new Human("Egor", true, 74);
Human deda2 = new Human("Mike", true, 75);
System.out.println(child1);
System.out.println(child2);
System.out.println(child3);
System.out.println(mother);
System.out.println(father);
System.out.println(baba1);
System.out.println(baba2);
System.out.println(deda1);
System.out.println(deda2);
}
public static class Human {
String name;
boolean sex;
int age;
Human father;
Human mother;
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 Human(String name, boolean sex, int age) {
this.name = name;
this.sex = sex;
this.age = age;
}
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;
}
}
}
Но если присваивать father-mother снизу то 4 строчки пропускает, а на 5й опять ошибка, очень не понятно
public static void main(String[] args) {
Human child1 = new Human("Anny", false, 10);
Human child2 = new Human("Lory", false, 16);
Human child3 = new Human("Emmy", false, 16);
Human mother = new Human("Mom", false, 45);
Human father = new Human("Dad", true, 50);
Human baba1 = new Human("Lena", false, 72, father, mother);
Human baba2 = new Human("Olya", false, 73, father, mother);
Human deda1 = new Human("Egor", true, 74, father, mother);
Human deda2 = new Human("Mike", true, 75, father, mother);