はいばらあい(灰原哀) 2021-07-09 21:09 采纳率: 25%
浏览 13

嗯问个bc的问题,错在哪里了?胡思乱想写出来的,刚学,格式是按ls教的写的。

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

}

img

  • 写回答

2条回答 默认 最新

  • zaocha 2021-07-09 21:10
    关注

    仔细查查

    评论

报告相同问题?

问题事件

  • 修改了问题 7月9日
  • 创建了问题 7月9日

悬赏问题

  • ¥300 寻抓云闪付tn组成网页付款链接
  • ¥15 请问Ubuntu要怎么安装chrome呀?
  • ¥15 视频编码 十六进制问题
  • ¥15 Xsheii7我安装这个文件的时候跳出来另一个文件已锁定文件的无一部分进程无法访问。这个该怎么解决
  • ¥15 unity terrain打包后地形错位,跟建筑不在同一个位置,怎么办
  • ¥15 FileNotFoundError 解决方案
  • ¥15 uniapp实现如下图的图表功能
  • ¥15 u-subsection如何修改相邻两个节点样式
  • ¥30 vs2010开发 WFP(windows filtering platform)
  • ¥15 服务端控制goose报文控制块的发布问题