/*
* main方法程序入口控制台
*/
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Ji a=new Ji("虫子","打鸣", "喔喔","芦花鸡");
a.print();
Bow b=new Bow("小鱼虾","斑嘴鸭","嘎嘎", "游泳");
a.print();
}
}
public class Cw {
/*
* 父类
* 存放共有属性类
*/
//定义变量
private String name ;
private String pz;
//get,set 封装方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPz() {
return pz;
}
public void setPz(String pz) {
this.pz = pz;
}
/*
* 定义带参方法
*/
public Cw(String name , String pz){
this.name =name;
this.pz=pz;
}
//带参方法输出
public void print(){
System.out.println("我是:"+name+"我叫"+pz);
}
}
public class Ji extends Cw {
/*
* 子类
* 小鸡类
*/
//定义变量
private String ah;
private String xw;
//get,set 方法
public String getAh() {
return ah;
}
public void setAh(String ah) {
this.ah = ah;
}
public String getXw() {
return xw;
}
public void setXw(String xw) {
this.xw = xw;
}
//带参构造方法
public Ji(String ah, String xw, String name, String pz) {
super(name, pz);
this.ah = ah;
this.xw = xw;
//特有属性输出
System.out.println("我吃"+ah);
System.out.println("我会"+xw);
}
}
public class Bow extends Cw {
/*
* 子类
* 鸭子类
*/
//定义方法
private String chi;
private String dz;
//get,set 方法封装
public String getChi() {
return chi;
}
public void setChi(String chi) {
this.chi = chi;
}
public String getDz() {
return dz;
}
public void setDz(String dz) {
this.dz = dz;
}
/*
* 带参构造方法
*/
public Bow(String chi , String dz,String name, String pz) {
super(name, pz);
this.chi = chi;
this.dz = dz;
//本类特有属性输出
System.out.println("我吃"+chi);
System.out.println("我会"+dz);
}
}