Java創建如下類和子類?
class Human{
public String IdCard;
public String Name;
Human(String ic,String Nam){
IdCard=ic;
Name=Nam;
}
void CanSpeak(){};
}
class Man extends Human{
String kind="Man";
Man(String ic, String Nam) {
super(ic, Nam);
}
void CanSpeak(){
System.out.println(Name+" "+kind+" "+IdCard+" can speak English");}
}
class Woman extends Human{
String kind="Woman";
Woman(String ic, String Nam) {
super(ic, Nam);
}
@Override
void CanSpeak(){
System.out.println(Name+" "+kind+" "+IdCard+" can speak Chinese");}
}
public class Test{
public static void main(String agrs[]){
Man m=new Man("1111","張三");
Woman w=new Woman("2222","小紅");
Human h=m;
m.CanSpeak();
w.CanSpeak();
h.CanSpeak();
}
}