Java创建如下类和子类

更新时间:01-25 教程 由 终止符 分享

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();

}

}

声明:关于《Java创建如下类和子类》以上内容仅供参考,若您的权利被侵害,请联系13825271@qq.com
本文网址:http://www.25820.com/tutorial/14_2205694.html