好开心

今天开通博客,大家常来关注

package com.tasko7; public class Pet { private String name; private int age; private String color; private double weight; public Pet(String name, int age, String color, double weight) { } public Pet() { } public String getName(){ return name; } public void setName(String name){ this.name = name; } public int getAge(){ return age; } public void setAge(int age){ this.age = age; } public String getColor(){ return color; } public void setColor(String color){ this.color = color; } public double getWeight(){ return weight; } public void setWeight(double weight){ this.weight = weight; } public void show(){ System.out.println(name+",今年"+age+"岁,是"+color+"颜色,体重是:"+weight+"千克。"); } public void speak(){ System.out.println(name+"说:我会说话,但是人类听不懂我在说什么!"); } public void eat(String food){ System.out.println(name+"喜欢吃"+food); } public void dogown(String onwer){ System.out.println(onwer+"和他的宠物"+name+"玩的好开心啊"); } public void jump(double height){ if(height > 10.0){ System.out.println(name+"真厉害跳的真高啊"); }else System.out.println(name+"一点也不厉害,跳的不高"); } public void run(double distance) { if (distance > 100.0) { System.out.println(name + "真厉害跑的真远啊"); } else System.out.println(name + "一点也不厉害,跑的不远"); } public void sleep(double distance) { if (distance > 3) { System.out.println(name + "睡的挺久的"); } else System.out.println(name + "睡的不久"); } } package com.task08; import com.tasko7.Pet; public class Cat extends Pet { private String species; public void setSpecies(String species){ this.species = species; } public String getSpecies(){ return species; } public Cat(){ this("弯弯","波斯"); } public Cat(String name,String species){ super.setName(name); this.species = species; } public Cat(String name,int age,String color,double weight,String species){ super(name,age,color,weight); this.species = species; } public void bash(){ System.out.println(super.getName()+"刚洗了个澡"); } public void catchMouse(int n){ System.out.println(super.getName()+"刚抓了只老鼠"); } } package com.task08; public class CatTest { public static void main(String[]args){ Cat cat = new Cat("咪咪",2,"白",3.0,"折耳"); cat.show(); cat.speak(); cat.eat("鱼"); cat.dogown("康康"); cat.jump(12.0); cat.run(101.0); cat.sleep(1); cat.bash(); cat.catchMouse(3); } } 输出结果为 null,今年0岁,是null颜色,体重是:0.0千克。 null说:我会说话,但是人类听不懂我在说什么! null喜欢吃鱼 康康和他的宠物null玩的好开心啊 null真厉害跳的真高啊 null真厉害跑的真远啊 null睡的不久 null刚洗了个澡 null刚抓了只老鼠 代码问题出现在宠物名称无法正常显示而是显示 null,告诉我这三段代码中哪里有错误并给出解决方案
最新发布
03-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值