0

Не могу сообразить в чем проблема, выдает: "return type void is not compatible with string interface java", я что то читал про одинаковые сигнатуры методов но так и не понял. Как мне решить данную проблему или в какую сторону копать.

public class Student implements Printable { 


    Student() {
         ...
    }


    public void doing() {
        System.out.printf(" что то делает ");
    }
}

class StudentDetails extends Student implements Printable {

    StudentDetails() {
        super()
         ...
    }

    public void doing(){
        System.out.println("делает что то вдобавок");
    }
}

interface Printable {

    void doing();

}

class Main {

public static void main(String[] arg) {
    Student st1 = new Student();
    Student st2 = new Student();
    Student st3 = new Student();
    Student st4 = new Student();
    Student st5 = new Student();

    Student[] students = new Student[5];
    students[0] = st1;
    students[1] = st2;
    students[2] = st3;
    students[3] = st4;
    students[4] = st5;

    for (int i = 0; i < students.length; i++) {
        System.out.println(students[i].doing());
    }

}

}

2 ответа 2

3

System.out.println ожидает, что вы передадите строку как параметр, а метод doing не возвращает ничего, поскольку он void.

Попробуйте

for (int i = 0; i < students.length; i++) {
    students[i].doing();
}
1
for (int i = 0; i < students.length; i++) {
    students[i].doing();
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.