CoreJava/exp4/PolymorphismTest.java

31 lines
1.1 KiB
Java
Raw Permalink Normal View History

2024-05-09 09:10:51 +08:00
package exp4;
public class PolymorphismTest {
public static void main(String[] args) {
Student[] studentArray = new Student[5];
studentArray[1] = new Undergraduate("鲁向东"); //本科生鲁向东
studentArray[0] = new Undergraduate("陈建平"); //本科生陈建平
studentArray[2] = new Postgraduate("匡晓华"); //研究生匡晓华
studentArray[3] = new Undergraduate("周丽娜"); //本科生周丽娜
studentArray[4] = new Postgraduate("梁欣欣"); //研究生梁欣欣
for (int i=0; i<studentArray.length;i++) {
studentArray[i].setCourseScore(0,87);
studentArray[i].setCourseScore(1,90);
studentArray[i].setCourseScore(2,78);
}
for (int i=0; i<5 ;i++) {
studentArray[i].calculateGrade();
}
System.out.println("姓名" + " 类型" +" 成绩");
System.out.println("-----------------------");
for (int i=0; i<5 ;i++) {
System.out.println(studentArray[i].getName( )+" "+
studentArray[i].getType( )+" "+
studentArray[i].getCourseGrade( ));
}
}
}