设计一个学生类Student,其属性有姓名,年龄,学历等

该博客展示了如何在Java中设计一个`Student`类,包括姓名、年龄和学历属性,并扩展了`Undergraduate`和`Graduate`子类,分别增加专业和研究方向属性。博主提供了代码实例,演示了如何创建学生对象并打印相关信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/**
 * 
 */
package mamin;

/**
 * @author 敏儿
 *@package_name:mamin
*@file_name:TestExtends.java
*@date-time:2017年10月15日下午4:10:27
*@location:https://github.com/1508010207/yinhang.git
 */
public class TestExtends {
		public static void main(String[] args) {
			Undergraduate stu1=new Undergraduate("马敏",20,"本科","软件工程");
	        Graduate stu2=new Graduate("赵宣",22,"硕士","网络工程");
	        stu1.show();
	        stu2.show();
		}
	}

/** * */package mamin;/** * @author 敏儿 *@package_name:mamin*@file_name:Student.java*@date-time:2017年10月15日下午4:00:07*@location:https://github.com/1508010207/yinhang.git */public class Student {//Student类private String name;//姓名private int age;//年龄private String education ;//学位public Student(String name, int age, String education) {//构造方法super();this.name = name;this.age = age;this.education = education;}public Student() {super();}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public String getEducation() {return education;}public void setDegree(String education) {this.education = education;}public void show(){System.out.println("姓名:" + this.getName() + ". 年龄:" + this.getAge() + ". 学位:" + this.getEducation() );}}class Undergraduate extends Student{//本科生类private String specialty;public String getSpecialty() {return specialty;}public void setSpecialty(String specialty) {this.specialty = specialty;}public Undergraduate(String name, int age, String education, String specialty) {super(name, age, education);this.specialty = specialty;}public Undergraduate(String name, int age, String education) {super(name, age, education);}public void show(){System.out.println("姓名:" + this.getName() + ". 年龄:" + this.getAge() + ". 学位:" + this.getEducation() + ". 专业:" + this.getSpecialty());}}class Graduate extends Student{//研究生类private String direction;//研究方向public String getDirection() {return direction;}public void setDirection(String direction) {this.direction = direction;}public Graduate(String name, int age, String Education, String direction) {super(name, age, Education);this.direction = direction;}public Graduate(String name, int age, String Education) {super(name, age, Education);}public void show(){System.out.println("姓名:" + this.getName() + ". 年龄:" + this.getAge() + ". 学位:" + this.getEducation() + ". 研究方向:" + this.getDirection());}/** * @return */public String getEducation() {// TODO Auto-generated method stubreturn null;}}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值