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