黑马程序员技术交流社区
标题:
为什么“吃肉”读取不出来
[打印本页]
作者:
MagicBoy
时间:
2014-3-18 23:26
标题:
为什么“吃肉”读取不出来
//父类
public class Animal {
String sleep,eat;
public Animal(){
System.out.println("睡觉");
//程序说吃肉未被读取。哪里出错了啊?
}
}
//子类
public class Lion extends Animal {
public Lion(String eat){
this.eat=eat;
System.out.println("狮子是吃"+this.eat);
}
public static void main(String[] args){
Rabbit a=new Rabbit("吃肉");
}
作者:
方青木
时间:
2014-3-19 00:10
Rabbit a=new Rabbit("吃肉");
应该是Lion a = new Lion("吃肉");
作者:
戒爱
时间:
2014-3-19 00:20
Rabbit不是一个类,不可创建实例对象
作者:
王竞
时间:
2014-3-19 00:22
朋友,你从哪里跑出来的Rabbit,你就没有定义Rabbit这个类啊
作者:
MagicBoy
时间:
2014-3-19 00:59
王竞 发表于 2014-3-19 00:22
朋友,你从哪里跑出来的Rabbit,你就没有定义Rabbit这个类啊
中间代码搞掉了,本来是定义了狮子和兔子两个类
作者:
Sage
时间:
2014-3-19 10:52
public class Inherit {
/**
* 继承
*/
public static void main(String[] args) {
new Lion("肉");
}
}
// 动物类
class Animal {
private String sleep;
private String eat;
public String getSleep() {
return sleep;
}
public void setSleep(String sleep) {
this.sleep = sleep;
}
public String getEat() {
return eat;
}
public void setEat(String eat) {
this.eat = eat;
}
public Animal() {
System.out.println("睡觉");
}
}
// 狮子类
class Lion extends Animal {
public Lion(String eat) {
System.out.println("狮子是吃" + eat);
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2