Выскакивает странная ошибка, говорит что отсутствует на 55 строчке "return", т.е. как метод "toString" должен возвращать значение, но в методе в зависимости от ситуации есть "return".
Сама ошибка: Метод должен возвращать значение. Возможно вы забыли оператор "return".
файл com/javarush/task/task06/task0621/Solution.java, строка 55, позиция 1659
package com.javarush.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Родственные связи кошек
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String grandFatherName = reader.readLine();
Cat catGrandFather = new Cat(grandFatherName);
String grandMotherName = reader.readLine();
Cat catGrandMother = new Cat(grandMotherName);
String fatherName = reader.readLine();
Cat catFarher = new Cat(fatherName, null, catGrandFather);
System.out.println(catGrandFather);
System.out.println(catGrandMother);
System.out.println(catFarher);
}
public static class Cat {
private String name;
private Cat mother;
private Cat father;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat mother, Cat father) {
this.name = name;
this.mother = mother;
this.father = father;
}
@Override
public String toString() {
if (mother == null && father == null)
return "The cat's name is " + name + ", no mother, no father";
else if (mother == null)
return "The cat's name is " + name + ", no mother, father is " + father;
else if (father == null)
return "The cat's name is " + name + ", mother is " + mother + ", no father";
}
}
}