當前位置:編程學習大全網 - 編程軟體 - java多態性的編程題目

java多態性的編程題目

public?class?People?{

private?String?name;

private?Integer?age;

private?String?phone;

public?String?getMessage()?{

return?"People:?姓名:"+name+",年齡:"+age+",電話:"+phone;

}

public?String?getName()?{

return?name;

}

public?void?setName(String?name)?{

this.name?=?name;

}

public?Integer?getAge()?{

return?age;

}

public?void?setAge(Integer?age)?{

this.age?=?age;

}

public?String?getPhone()?{

return?phone;

}

public?void?setPhone(String?phone)?{

this.phone?=?phone;

}

}public?class?Student?extends?People{

private?Integer?id;

public?String?getMessage(Integer?id)?{

return?"Student:?姓名:"+super.getName()+",年齡:"+super.getAge()+",電話:"+super.getPhone()+",學號:"+id;

}

public?Integer?getId()?{

return?id;

}

public?void?setId(Integer?id)?{

this.id?=?id;

}

}public?class?S?{

public?static?void?main(String[]?args)?{

Student?student?=?new?Student();

student.setId(13);

student.setName("李三");

student.setAge(18);

student.setPhone("123-4567-8901");

System.out.println(student.getMessage(student.getId()));

}

}

  • 上一篇:成都越凡創新科技有限公司怎麽樣?
  • 下一篇:歐姆龍plc做溫度控制作用,如何獲得溫度的數字量
  • copyright 2024編程學習大全網