public class Student {
int marks;
String name;
char sex;
String email;
}
Student[] s = new Student[10];
public class StudentDemo {
Student s[] = new Student[10];// array Student//
Student s1 = new Student();// Student Object//
s1.setName("John"); //Eclipse says here there is a mistake an ask to delete John//
Student[0]=s1;
}
我创建了一个具有名称和其他属性的Student类。但是现在我想用Student对象初始化数组的每个元素。这段代码是否正确? Eclipse会抛出很多红点。 帮助。用Student对象初始化数组中的每个元素
你需要在一些方法里面写这段代码。你不能直接在类中写逻辑。 – 2014-09-27 07:53:23
使用s [0] = s1;而不是Student [0] = s1 ;. – KernelPanic 2014-09-27 07:53:53