对于一个任务,我被要求致力于调用一个类并创建一个数组对象,这是我在这里做的;在BlueJ中打印对象阵列
public void DVDArrayObjects() {
//creates variables
int i;
DVDClass[] dvdArray = new DVDClass[5];
//reference to DVDClass
for (i = 0; i < 2; i ++) {
//create new instance of calling the class
dvdArray[i] = new DVDClass();
//create new instance of getting the info
dvdArray[i].getDVDInfo();
//display
//System.out.println(dvdArray[i]);
}
}
创建对象数组的工作正常,但显示不。它显示了我运行它时的内存分配情况。我真的被困在如何让它显示。
**编辑**
当我使用System.out.println(dvdArray[i].getDVDInfo());
错误void types not allowed in here
显示出来
**编辑完**
任何帮助都将不胜感激。
你的错误是因为'getDVDInfo()'不返回任何东西,这是'void' –
无法打印“无”(无效)。你需要你的'getDVDInfo()'来'返回'一些东西。 –
最好的选择是覆盖toString() –