阿123斌 2017-09-28 08:17 采纳率: 100%
浏览 804

请教大神this继承的问题

public class Test {

static Animal[] animals = new Animal[3];

public static void main(String[] args) {

    animals[0] = new Cat("加菲猫",4);
    animals[1] = new Ya("唐小鸭",2);
    animals[2] = new Shark("小鲨",0);

    Scanner input = new Scanner(System.in);


            System.out.println("动物名字\t\t腿的条数\t\t动物叫");
            for (int i = 0; i < animals.length; i++) {
                System.out.println(animals[i].getName() + "\t\t" +animals[i]. + "\t\t"+ animals[i].print());
            }



            public class Cat extends Animal implements leng {
private int strain;

public Cat(String name, int strain) {
    super(name);
    this.strain = strain;
}


public String print() {
    String speak = "喵喵喵....";
    return speak;
}
为什么引用子类构造并赋值时子类的那个this.strain没有显示值
  • 写回答

7条回答 默认 最新

  • return_bug 2017-09-28 09:27
    关注

    请问下楼主 能否给出全部的源码 方便进行调试查看原因

    评论

报告相同问题?

悬赏问题

  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键