데이터 멤버가 이름(이름), 나이(나이) 및 학위(학위)인 학생 클래스를 디자인합니다. Student 클래스에서 학부 클래스 Undergraduate 및 대학원 클래스가 파생되고, 학부 클래스 Unde

주제 정보:

  1. 데이터 멤버가 이름(이름), 나이(나이) 및 학위(학위)인 학생 클래스를 디자인합니다. 학부 클래스와 대학원 클래스는 Student 클래스에서 파생되며, 학부 클래스 Undergraduate는 회원 전공(Professional)을 추가하고, 대학원 클래스는 회원 방향(연구 방향)을 추가합니다. 각 클래스에는 데이터 멤버 정보를 출력하기 위한 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 ;
    }

}

рекомендация

отblog.csdn.net/guankunkunwd/article/details/121675778