实 验 报 告
( 2017 / 2018学年 第2学期)
课程名称
JAVA语言程序设计
实验名称
Java集成开发环境的安装与使用、
Java变量、表达式与控制结构
实验时间
2018
年
4
月
11
日
指导单位
计算机学院软件教学中心
指导教师
许棣华
学生姓名
王利国
班级学号
B160209
学院(系)
电子与光学工程学院,微电子学院
专 业
微电子科学与工程
实验名称
方法、数组和类
指导教师
许棣华
实验类型
上机
实验学时
2
实验时间
2017.4.11
三、实验内容
1. 在前面实验二已定义的学生类Student的基础上,以Student类为父类,为学生类派生出一个子类为大学生类(CollegeStudent)。
CollegeStudent 类在学生类上增加一个专业(profession)数据属性;方法上增加获得专业和设置专业两个方法。并对超类中的toString( )方法进行重写,使得CollegeStudent类中的toString( )方法除了显示学生类的信息外,还要显示它的专业属性。
编写测试程序的主类。在主类中创建一个Student对象和CollegeStudent对象,并显示或修改这两个对象的属性值。
packagelg.test;//测试类
public classDemo31 {public static voidmain(String[] args) {
Student one= new Student( "16020912", "王宁宁","男" , 19);
CollegeStudent two= new CollegeStudent( "16020913", "王利国","男" , 19 ,"微电子科学与工程");
System.out.println("未进行修改的时候的属性值");
System.out.println(one.toString());
System.out.println(two.toString());
System.out.println("修改后的属性值");
one.setAge(20);
two.setProfession("微电子");
System.out.println(one.toString());
System.out.println(two.toString());
}
}classStudent {privateString studentID;privateString name;privateString sex;private intage;private static intcount;public static intgetCount() {returncount;
}
Student(String studentID, String name, String sex,intage) {this.studentID =studentID;this.name =name;this.sex =s