谁能麻烦帮看一眼code啊。。。谢谢了,,,就几行。。谢谢了 import java.lang.String; public class StudentTestr { public static void main(String[] args) { String[] student = new String[3]; student[].inputStudentDetails(); 这行报错。。。。
String[] student = new String[3]; student是一个数组对象, 数组对象又怎么会有inputStudentDetails()这个方法呢? 这个方法应该是 Student.java里面的才对,所以,你应该这样: String[] students = new String[]{new Student(),new Student(),new Student()}; for(Student stu:students){ stu.inputStudentDetails(); }
------解决方案--------------------
Java code
String[] student = new String[3]; //String?不是Student类型?
student[].inputStudentDetails(); //这里应该用数组的某个元素
//至少应该是这样的形式
Student student = new Student[3];
student[0] = new Student();
student[0].inputStudentDetails();
------解决方案--------------------
------解决方案--------------------
Java code
public class StudentTestr
{
public static void main(String[] args)
{
Student[] student = new Student[]{new Student(),new Student(),new Student()};
int index = 0;
while(index<student.length)
{
student[index].inputStudentDetails();
index = index +1;
}
}
}
class Student{//放你的Student内容。
public void inputStudentDetails() {
System.out.println("i am a student");
}
}
------解决方案--------------------