トピック情報:
- データメンバーが名前(名前)、年齢(年齢)、学位(学位)である学生クラスStudentを設計します。学部クラスと大学院クラスの卒業生は学生クラスから派生し、学部クラスの学部生はメンバーの専門分野(プロフェッショナル)を追加し、大学院のクラスはメンバーの方向性(研究の方向性)を追加します。各クラスには、データメンバー情報を出力するためのshow()メソッドがあります。最後に、次の情報を出力してください。
参照回答:
public class Student_1202 {
String name;
int age;
String degree;
public String show () {
return
"姓名:" + name + '\'' +
", 年龄:" + age +
", 学位:" + degree + '\'' +
'}';
}
public Student_1202 (String name, int age, String degree) {
this.name = name;
this.age = age;
this.degree = degree;
}
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 static void main (String[] args) {
Undergraduate zhangsan=new Undergraduate ("张三", 20,"本科","通信");
Undergraduate lisi=new Undergraduate ("李四",21,"本科","电子");
diection wangwu=new diection ("王五",25,"硕士","通信");
diection liuliu=new diection ("刘六",36,"博士","通信");
System.out.println (zhangsan.show ());
System.out.println (lisi.show ());
System.out.println (wangwu.show ());
System.out.println (liuliu.show ());
}
}
class Undergraduate extends Student_1202{
String sepcialty;
public Undergraduate (String name, int age, String degree, String sepcialty) {
super (name, age, degree);
this.sepcialty = sepcialty;
}
@Override
public String show () {
return
"姓名:" + this.name +" "+
" 年龄:" + this.age + " "+
" 学位:" + this.degree + " " +"专业:"+this.sepcialty ;
}
}
class diection extends Student_1202{
String sepcialty;
public diection(String name, int age, String degree, String sepcialty) {
super (name, age, degree);
this.sepcialty = sepcialty;
}
@Override
public String show () {
return
"姓名:" + this.name +" "+
" 年龄:" + this.age + " "+
" 学位:" + this.degree + " " +"研究方向:"+this.sepcialty ;
}
}