# 设计学生类Student和它的一个子类Undergraduate

<p>设计一个学生类Student和它的一个子类Undergraduate&#xff0c;要求如下&#xff1a;
(1)Student类有name和age属性&#xff0c;一个包含两个人参数的构造器&#xff0c;用于给两属性赋值&#xff0c;一个show()方法打印Student的属性信息。
(2)本科生类Undergraduate增加一个degree(学位)属性。有一个包含三参数的构造器&#xff0c;前两个参数用于给集成的属性赋值&#xff0c;第三个参数给degree专业见值&#xff0c;一个show()方法用于打印Undergraduate的属性信息。
(3)在测试类中分别打印Undergraduate和Student对象&#xff0c;调用它们的show()
 </p>

## template

```java
package T1;
public class Test {
	public static void main(String[] args) {
		Student stu = new Student("student", 100);
		stu.show();
		Undergraduate undergraduate = new Undergraduate("Undergraduate", 20, "本科");
		undergraduate.show();
	}
}
class Student {
	private String name;
	private int age;
	public Student() {
		super();
	}
	public Student(String name, int age) {
		this.name = name;
		this.age = age;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public double getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public void show() {
		System.out.println("名字：" + this.name + "\t年龄：" + this.age);
	}
}
class Undergraduate extends Student {
	private String degree;
	public Undergraduate(String name, int age, String degree) {
		super(name, age);
		this.degree = degree;
	}
	public void show() {
		System.out.println("名字：" + super.getName() + "\t年龄：" + super.getAge() + "\t学位:" + this.degree);
	}
}
```

## 答案

```java

```

## 选项

### A

```java

```

### B

```java

```

### C

```java

```