public class Cat extends Animal {
    private int lovely;

    public Cat() {
        super();
        this.lovely = 0;
    }

    public Cat(String name, int age, String gender, int lovely) {
        super(name, age, gender);
        this.lovely = lovely;
    }

    public void catchMouse() {
        System.out.println('猫正在抓老鼠!');
    }

    @Override
    public void eat() {
        System.out.println('猫正在吃鱼!');
    }
}
Java 猫类 Cat 继承 Animal 类:实现抓老鼠和吃饭功能

原文地址: https://www.cveoy.top/t/topic/nQJI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录