有这样类似的代码嘛,有点疑惑,不是很会做这个。大概是什么样子的呢?
public class Animal {
private Integer weight;
private String color;
/**
* 无参构造方法
*/
public Animal() {
}
/**
* 全参构造方法
* @param weight
* @param color
*/
public Animal(Integer weight, String color) {
this.weight = weight;
this.color = color;
}
public Integer getWeight() {
return weight;
}
public void setWeight(Integer weight) {
this.weight = weight;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}
public class Bird extends Animal{
/**
* 无参构造方法
*/
public Bird() {
}
/**
* 全参构造方法
*
* @param weight
* @param color
*/
public Bird(Integer weight, String color) {
super(weight, color);
}
public void fly(){
System.out.println("fly");
}
public static void main(String[] args) {
Bird bird = new Bird(10, "white");
bird.fly();
}
}
创建类,添加属性,然后加几个方法,再创建类继承一下