谁能麻烦帮看一眼code啊。。。谢谢了,,,就几行。。谢谢了
import java.lang.String;
public class StudentTestr
{
public static void main(String[] args)
{
String[] student = new String[3];
student[].inputStudentDetails(); 这行报错。。。。
}
}
如何调用另一个studentclass里的inputStudentDetails()的method啊???
student class 里面都compile一切正常。。。
[解决办法]
student[0].inputStudentDetails();
[解决办法]
studentclass啥样
String[] student = new String[3];是啥意思
[解决办法]
写错了吧?
是不是应该是
Student[] student = new Student[3];
如果要调用student数组里面第一个元素的inputStudentDetails()方法,应该
student[0].inputStudentDetails(); //当然,必须先给student数组传入对象,否则会报空指针
[解决办法]
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();
}
[解决办法]
String[] student = new String[3]; //String?不是Student类型?student[].inputStudentDetails(); //这里应该用数组的某个元素//至少应该是这样的形式Student student = new Student[3];student[0] = new Student();student[0].inputStudentDetails();
[解决办法]
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"); }}
[解决办法]