在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ 【JAVA小白】 關(guān)于繼承的構(gòu)造方法傳參數(shù)的問題。

【JAVA小白】 關(guān)于繼承的構(gòu)造方法傳參數(shù)的問題。

代碼如下:

abstract class Animal {
    int age;
    public Animal() {};
    public Animal(int age) {
        this.age = age;
    }
}

class Bird {
    public Bird(int age) {
        super(age);
        System.out.println("我是一直紅色的鳥!");
        System.out.println("我今年" + age + "歲了!");
    }
}

class Fish {
    public Fish(int age) {
        super(age);
        System.out.println("我是一直5斤重的魚!");
        System.out.println("我今年" + age + "歲了!");
    }
}

public class Test {
    public static void main(String[] args) {
        Bird bird = new Bird();
        Fish fish = new Fish();
    }
}

執(zhí)行結(jié)果如下:

clipboard.png

沒看出程序有什么毛病,我傳值的時(shí)候就是傳的1個(gè),怎么會(huì)說我沒有參數(shù)呢?

回答
編輯回答
巴扎嘿

你沒有寫extends啊
class Fish extends Animal{...}

2018年8月3日 12:13