collegestudent.java
来自「java继承类的使用 java继承类的使用」· Java 代码 · 共 53 行
JAVA
53 行
/**
* @(#)CollegeStudent.java
*
*
* @author
* @version 1.00 2008/3/31
*/
import student.Student;
public class CollegeStudent extends Student {
private String stuPro;
public CollegeStudent(String sno,String scl,String sna,String ssx,int sag,String pro) {
super(sno,scl,sna,ssx,sag);
setStuPro(pro);
}
public String getStuPro(){
return this.stuPro;
}
public void setStuPro(String pro){
this.stuPro=pro;
}
//对超类中的toString方法进行重写
public String toString(){
return super.getStuNo()+super.getStuClass()+super.getStuName()+super.getStuSex()+super.getStuAge()+this.stuPro;
}
}
//测试程序的主类
class TestMainCollegeStudent{
public static void main (String[] args) {
Student stu=new Student("2008001","计算机1班","张三","男",24);
CollegeStudent colStu=new CollegeStudent("2005180028","05计科","小明","女",22,"计算机科学与技术");
System.out.println("两个学生的原始信息如下:");
System.out.println("第一个学生:"+stu.toString());
System.out.println("第二个学生:"+colStu.toString());
System.out.println();
stu.setStuName("小张");
colStu.setStuPro("信息管理与信息系统专业");
colStu.setStuNo("2005181028");
colStu.setStuName("小吕");
System.out.println("两个学生的修改后的信息如下:");
System.out.println("第一个学生:"+stu.toString());
System.out.println("第二个学生:"+colStu.toString());
System.out.println();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?