abstract class Dept
{
String id;
String name;
String type;
String description;
Dept(){};
Dept(String id,String type,String description){
id=this.id;
type=this.type;
description=this.description;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getDesciption() {
return description;
}
public void setDesciption(String desciption) {
this.description = desciption;
}
}
class OutpatientDept extends Dept
{
String adress;
OutpatientDept(){}
OutpatientDept(String id,String name,String type,String adress){
id=this.id;
name=this.name;
type=this.type;
adress=this.adress;
}
public String toString() {
return "编号:"+id+"名称:"+name+"类型:"+type+"描述:"+description+"地址:"+adress;
}
}
class InpatientDept extends Dept{
String ward;
InpatientDept(){}
InpatientDept(String id,String name,String type,String ward){
id=this.id;
name=this.name;
type=this.type;
ward=this.ward;
}
public String toString() {
return "编号:"+id+"名称:"+name+"类型:"+type+"描述:"+description+"病区:"+ward;
}
}
class Hospital
{
static Dept[] Array=new Dept[100];
static void showDept(Dept Array[]) {
for(int i=0;i<Array.length;i++)
{
Array[i].toString();
}
}
static void addDept(Dept Array[],Dept addDept){
int i=Array.length;
Array[i]=addDept;
}
static void delDept(Dept Array[],int d){
for(int i=d;i<Array.length;i++)
{
Array[i-1]=Array[i];
}
}
}
public class Mock{
public static void main(String[] args) {
OutpatientDept o1=new OutpatientDept("2021001","001","aa","aaaa");
OutpatientDept o2=new OutpatientDept("2021002","002","bb","bbbb");
OutpatientDept o3=new OutpatientDept("2021003","003","cc","cccc");
InpatientDept i1=new InpatientDept("20210001","1001","aaa","aaaaa");
InpatientDept i2=new InpatientDept("20210002","1002","bbb","aaaaa");
InpatientDept i3=new InpatientDept("20210003","1003","bbb","aaaaa");
Hospital.Array[0]=o1;
Hospital.Array[1]=o2;
Hospital.Array[2]=o3;
Hospital.Array[3]=i1;
Hospital.Array[4]=i2;
Hospital.Array[5]=i3;
Hospital.showDept(Hospital.Array);
}
}
是重写的toString函数调用失败吗