А как мне распечатать передаваемый объект в конструктор?
Human(String name,boolean sex,int age){
this.name=name;
this.sex=sex;
System.out.println(new Human);
}
package com.javarush.task.task07.task0724;
/*
Семейная перепись
*/
public class Solution {
public static void main(String[] args) {
Human grandFather1 = new Human("sad",true,23);
}
public static class Human {
String name;
boolean sex;
int age;
Human father;
Human mother;
Human(String name,boolean sex,int age){
this.name=name;
this.sex=sex;
System.out.println(this.Human);
}
Human(String name,boolean sex,int age, Human father, Human mother){
this.name=name;
this.sex=sex;
System.out.println(name);
}
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;
}
}
}