设计一个学生类Student

package 第四章;
/*
File name:TestStudent.cpp
Author:杨柳
Date:2017/10/11
IDE:eclipse
description:学生类
github:
*/
public class TestStudent {
	public static void main(String agsp[]){
		Student stu=new Student("杨柳",18,"高中");
		stu.show();
		System.out.print("-------------------------");
		System.out.println();
		Undergraduate under=new Undergraduate("王梦凡",22,"本科","软件工程");
		under.show();
		System.out.print("-------------------------");
		System.out.println();
		Graduate gra=new Graduate("王志云",26,"研究生","人工智能");
		gra.show();
	}

}
 class Student{  //学生类Student
	 String name; //姓名 
	 int age; //年龄
	 String education; //学历
	 Student(String na, int ag, String edu) { //构造方法
		this.name = na;
		this.age = ag;
		this.education = edu;
	 }
	 public void show() { 
		 System.out.println("姓名:"+name+"  "+"年龄:"+age+"  "+"学历:"+education);
	 }
 }
 
 class Undergraduate extends Student{ //本科生类
     String specialty;
	 Undergraduate(String na, int ag, String edu,String spe) {
		super(na, ag, edu);
		this.specialty = spe;
		// TODO 自动生成的构造函数存根
	} 
	 public void show() { 
		 super.show();
		 System.out.println("专业:"+specialty);
	 }
 }
 class Graduate extends Student{ //研究生
        String direction;
	    Graduate(String na, int ag, String edu,String dir) {
		super(na, ag, edu);
		this.direction=dir;
		// TODO 自动生成的构造函数存根
	}
		 public void show() { 
			 super.show();
			 System.out.println("研究方向:"+direction);
		 }   
	 
 }
 

2.设计一个学生类Student,其属性有:姓名(name)、 年龄 (age)、 学历 (education), 由Student类派生出本科生类Undergraduate和研究生类Graduate,本科生类增加属性:专业 (specialty), 研究生类增加属性:研究方向 (direction)。 每个类都有构造方法和用于输出属性信息的show () 方法,在测试类TestExtends中测试输出
  • 4
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值