Что я получаю вместо этого:
null < /p>
То, что я пробовал: < /p>
двойная проверка, что значения конструктора не являются нулевыми. < /P>
prys press press pryfully warry presemly до возврата. /> Убедитесь, что я импортирую java.util.arrays. < /p>
среда: < /p>
java версия: 17 < /p>
ide: Intellij Idea < /p>
Что я делаю здесь неправильно?
Код: Выделить всё
public class Subject {
private String subjectCode;
private String subject;
private String duration;
private String credits;
private String amount;
public Subject(String subjectCode, String subject, String duration, String credits, String amount) {
this.subjectCode = subjectCode;
this.subject = subject;
this.duration = duration;
this.credits = credits;
this.amount = amount;
}
public String[] toArray() {
return new String[]{subjectCode, subject, duration, credits, amount};
}
}
< /code>
И вот как я это называю: < /p>
Subject math = new Subject("MATH101", "Mathematics", "6 months", "15", "R2000");
String[] data = math.toArray();
System.out.println(Arrays.toString(data));
< /code>
Что я ожидаю:
Я ожидаю печати консоли:
[MATH101, Mathematics, 6 months, 15, R2000]Подробнее здесь: https://stackoverflow.com/questions/796 ... initialize