源代码:
package jichen;
public class Person {
int studentNumber;
String gender;
String name;
String Department;
String Major;
int score;
void setName(){
System.out.println("姓名:"+name);
}
void setScore(){
System.out.println("成绩:"+score);
}
void setDepartment(){
System.out.println("部门:"+Department);
}
void setMajor(){
System.out.println("专业:"+Major);
}
public static void main(String[] args) {
Person s1 = new Student1();
s1.studentNumber=1610113000;
s1.gender="大一";
s1.name="Tom";
s1.score=99;
s1.Department="计算机";
s1.Major="软件";
s1.setName();
System.out.println("年级:"+s1.gender);
System.out.println("学号:"+s1.studentNumber);
s1.setScore();
s1.setDepartment();
s1.setMajor();
}
class Student1 extends Person {
String department;
String major;
void setDepartment(){
System.out.println("系别:"+department);
}
void setMajor(){
System.out.println("专业:"+major);
}
实验心得:
1.在实验开始审题时出现了错误,导致开始敲出的程序出现了一些错误
2.通过实验调试我进一步了解了继承和多态的概念
3.在实验中有许多逻辑错误,程序只是完成了一部分,还有待改善。