Java中程序中定义一个学生班和一个研究生班,这是从学生派生的并且是主要班级。 2)学生有两个字段:学生的ID和姓名,这是通过学生的构造函数初始化的。

定义一个class Student和一个class Graduate,这是从继承Student的,并且是主类。

2)学生有两个字段:学生的ID和姓名,这是通过学生的构造函数初始化的。
3)覆盖toString方法,让print(一个实例)产生类似“学号:101姓名:David Bissell”的输出。
4)毕业生有一个领域:主管,可通过“毕业生”进行初始化

Define a Student class and a Graduate class which is derived from the Student and is the main class.
2) Student has two fields: student’s Id and name, which are initialized through Student’s constructor.
3) Override toString method, let print(an instance) produce an output like “学号:101 姓名:David Bissell”.
4) Graduate has one field: supervisor, which is initialized through Graduate’

class Student{
	int Id;
	String name;
	public Student(int Id,String name) {
		this.Id=Id;
		this.name=name;
	}
	public String toString() {
		return "name:  "+name+"Id:"+Id;
	}
}
public class Graduate extends Student{
	String supervisor;
     public Graduate(int Id, String name,String supervisor) {
		super(Id, name);
		this.supervisor=supervisor;
	}

public static void main(String[] args) {
		Graduate stu=new Graduate(101,"David Bissell","Jeff Trump");
		System.out.print(stu+" 导师:"+stu.supervisor);
		}

	}



运行结果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值