Java创建DegreeDemo_java程序填空题!!!设计一个学生类Student,其属性有name(姓名)、age(年龄)和degree(学位)。...

这篇博客展示了如何在Java中设计一个Student类,包含姓名、年龄和学位属性,并扩展了两个子类Undergraduate和Graduate,分别增加专业和研究方向属性。通过构造函数初始化实例,并提供getter和setter方法进行属性访问。在main方法中创建了两个实例并打印了相关信息。
摘要由CSDN通过智能技术生成

展开全部

class Student{

private String name;

private int age;

private String degree;

public Student(String name, int age, String degree) {

e69da5e887aa3231313335323631343130323136353331333361303064super();

this.name = name;

this.age = age;

this.degree = degree;

}

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 getDegree() {

return degree;

}

public void setDegree(String degree) {

this.degree = degree;

}

public void show(){

System.out.println("姓名:" + this.getName() + ". 年龄:" + this.getAge() + ". 学位:" + this.getDegree() );

}

}

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 degree, String specialty) {

super(name, age, degree);

this.specialty = specialty;

}

public Undergraduate(String name, int age, String degree) {

super(name, age, degree);

}

public void show(){

System.out.println("姓名:" + this.getName() + ". 年龄:" + this.getAge() + ". 学位:" + this.getDegree() + ". 专业:" + 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 degree, String direction) {

super(name, age, degree);

this.direction = direction;

}

public Graduate(String name, int age, String degree) {

super(name, age, degree);

}

public void show(){

System.out.println("姓名:" + this.getName() + ". 年龄:" + this.getAge() + ". 学位:" + this.getDegree() + ". 研究方向:" + this.getDirection());

}

}

public class exp1401 {

public static void main(String[] args) {

Undergraduate stu1=new Undergraduate("张三",23,"本科","工业自动化");

Graduate stu2=new Graduate("李四",27,"硕士","网络技术");

stu1.show();

stu2.show();

}

}

a59d1ac8292b40b50310b66f914c3aa3.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值