一·父类
package Pa_001;
public class Animal {
/**
* 父类,动物类
* @author
*
*/
private String type;//种类
private char sex;//性别
private String addr;//产地
private String color;//颜色
private String food;//食物
private String sound;//声音
public Animal() {
super();//调到父类object类的构造方法
// TODO Auto-generated constructor stub
}
public Animal(String type, char sex, String addr) {
super();
this.type = type;
this.sex = sex;
this.addr = addr;
}
public Animal(String type, char sex, String addr, String color) {
super();
this.type = type;
this.sex = sex;
this.addr = addr;
this.color = color;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this.addr = addr;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
/**
* 子类,方法的重写(覆盖)
* 1.特征:方法名,参数,返回值必须一致
* 2.子类的修饰符不能比父类的窄
* 3.类超出的异常不能比父类多
*/
public void breath(){
}
public void food(){
}
public void sound(){
}
public void addr(){
}
}
二。子类
package Duotai;
public class Dog extends Dongwu {
public void food(){
System.out.println(“骨头”);
}
public void sound(){
System.out.println(“汪汪”);
}
}