I have a getSubjects method in a Student class which is overridden in the subclasses.
I am trying to print the array using the getSubjects method.
The main class code is:
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 This is the getSubjects methods:
public String getSubjects(){ return(" Science Student >> " + "Physics Grade: " + physicsGrade + " Astronomy Grade: " + astronomyGrade); }