package eclipse;
public class Pet {
String color;
int weight;
void setcolor() {
}
void setweight() {
}
}
package eclipse;
public class Cat extends Pet{
private String color;
private double weight;
void setcat(String color,double weight) {
this.color=color;
this.weight=weight;
}
String getcolor() {
return color;
}
void setcolor() {
System.out.println("猫的颜色是:"+getcolor());
}
double getweight() {
return weight;
}
void setweight() {
System.out.println("猫的体重是:"+getweight());
}
}
package eclipse;
public class Dog extends Pet{
private String color;
private double weight;
void setdog(String color,double weight) {
this.color=color;
this.weight=weight;
}
String getcolor() {
return color;
}
void setcolor() {
System.out.println("狗的颜色是:"+getcolor());
}
double getweight() {
return weight;
}
void setweight() {
System.out.println("狗的体重是:"+getweight());
}
}
package eclipse;
public class Rabbit extends Pet{
private String color;
private double weight;
void setrabbit(String color,double weight) {
this.color=color;
this.weight=weight;
}
String getcolor() {
return color;
}
void setcolor() {
System.out.println("兔子的颜色是:"+getcolor());
}
double getweight() {
return weight;
}
void setweight() {
System.out.println("兔子的体重是:"+getweight());
}
}
package eclipse;
public class 测试类 {
static String white;
public static void main(String[] args) {
Dog dog=new Dog();
dog.setcolor();
dog.setdog(white, 127.8);
dog.setcolor();
dog.getweight();
dog.setweight();
Rabbit rabbit=new Rabbit();
rabbit.setrabbit(white, 79.5);
rabbit.setcolor();
rabbit.getweight();
rabbit.setweight();
Cat cat=new Cat();
cat.setcat(white, 84.6);
cat.getcolor();
cat.setcolor();
cat.getweight();
cat.setweight();
}
}