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();
}
}
Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有