我在Student
类中有getSubjects
方法,该类在子类中被覆盖。我想用getSubjects
方法打印数组。从数组中打印
主类代码:
package javalab5;
import java.util.*;
/**
*
* @author Saj
*/
public class JavaLab5 {
public static final int DEBUG = 0;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Student s[] = new Student[10];
s[0] = new MathStudent(14,15);
s[1] = new MathStudent(16,19);
s[2] = new MathStudent(18,21);
s[3] = new MathStudent(23,28);
s[4] = new ScienceStudent(32,25);
s[5] = new ScienceStudent(28,56);
s[6] = new ScienceStudent(29,28);
s[7] = new ComputerStudent(25,38);
s[8] = new ComputerStudent(34,39);
s[9] = new ComputerStudent(45,56);
int numberOfStudents = 0;
for (int loop = 0; loop < numberOfStudents; loop++) {
System.out.print("Student "+ loop + " >>");
System.out.println(s[loop].getSubjects());
}
}
}
UPDATE 这是getSubjects
方法:
public String getSubjects(){
return(" Science Student >> " + "Physics Grade: " + physicsGrade
+ " Astronomy Grade: " + astronomyGrade);
}
你的getSubjects()方法返回一个数组吗? –
@Surace请参阅getSubject方法的更新,它不返回数组。 – donk2017
那么...你的问题是什么呢? – azurefrog