第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如圖,可以給個代碼的思路嗎?

如圖,可以給個代碼的思路嗎?

青春有我 2023-04-10 16:12:50
編寫一個程序描述以下類層次 ,其中人為一個抽象類,其屬性包括:姓名、性別、出生日期等 。?教師包括任課學校、類別(大學、中學、小學)屬性;?學生為一抽象類,其屬性包括學校、學號、年級;?大學生包括專業(yè)、年級屬性;中學生包括年級屬性;小學生也包括年級屬性。每個類設計相應的構造方法和toString()方法,子類的toString()方法也可以調用父類的toString()方法。?在main方法中創(chuàng)建一個教師和2個學生對象,輸出對象信息。
查看完整描述

1 回答

?
蕭十郎

TA貢獻1815條經(jīng)驗 獲得超13個贊

public class Test {

public static void main(String[] args) {

Teacher teacher = new Teacher("Wang Laoshi", false, 19910123, "qinghua", 3);
System.out.println(teacher.toString());

CollegeStudent collStu = new CollegeStudent("College Student", true, 19851231, "Beijingdaxue","001", 2, "Computer", 3);
System.out.println(collStu.toString());

MiddleSchStudent middStu = new MiddleSchStudent("Middle schoole student", false, 19910705, "Di yi zhongxue", "002", 17, "English", 5);
System.out.println(middStu.toString());
}

}

abstract class Person {
protected String name;
protected boolean sex;
protected int birthday;

public Person(){}

public Person(String name, boolean sex, int birthday){
this.name =name;
this.sex = sex;
this.birthday = birthday;
}

public String toString(){
return "name:" + name + ", sex:" + sex + ", birthday: " + birthday;
}
}

class Teacher extends Person{
private String school;
private int schoolType;

public Teacher(){

}

public Teacher(String name, boolean sex, int birthday, String school, int schoolType){
super(name, sex, birthday);
this.school = school;
this.schoolType = schoolType;
}

public String toString(){
return super.toString() + ", school: " + school + ", school type: " + schoolType;
}
}

abstract class Student extends Person{
protected String school;
protected String no;
protected int grade;

public Student(){

}

public Student(String name, boolean sex, int birthday, String school, String no, int grade){
super(name, sex, birthday);
this.school = school;
this.no = no;
this.grade = grade;
}

public String toString(){
return super.toString() + ", school:" + school + ", student no: " + no + ", studeng grade: " + grade;
}

}

class CollegeStudent extends Student{
private String major;
private int grade;

public CollegeStudent(){

}

public CollegeStudent(String name, boolean sex, int birthday, String school, String no, int grade, String major, int colledgeGrade){
super(name, sex, birthday,school, no,grade);
this.major = major;
this.grade = colledgeGrade;
}

public String toString(){
return super.toString() + ", major:" + major + ", grade: " + grade;
}

}
class MiddleSchStudent extends Student{
private int grade;

public MiddleSchStudent(){

}

public MiddleSchStudent(String name, boolean sex, int birthday, String school, String no, int grade, String major, int colledgeGrade){
super(name, sex, birthday,school, no,grade);
this.grade = colledgeGrade;


public String toString(){
return super.toString() + ", grade: " + grade;
}

}

---------------測試
name:Wang Laoshi, sex:false, birthday: 19910123, school: qinghua, school type: 3
name:College Student, sex:true, birthday: 19851231, school:Beijingdaxue, student no: 001, studeng grade: 2, major:Computer, grade: 3
name:Middle schoole student, sex:false, birthday: 19910705, school:Di yi zhongxue, student no: 002, studeng grade: 17, grade: 5


查看完整回答
反對 回復 2023-04-12
  • 1 回答
  • 0 關注
  • 290 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號