黑马程序员技术交流社区
标题:
老是忘记注释,,,,,
[打印本页]
作者:
韩凯5354
时间:
2015-8-31 18:53
标题:
老是忘记注释,,,,,
class Demo_Animal {
public static void main(String[] args) {
Mao m = new Mao();
m.setColor("白色");
m.setLeg(4);
System.out.println("颜色:"+m.getColor()+",腿:"+m.getLeg());
m.chifan();
m.catchMouse();
System.out.println("-----------------------------");
Mao m1 = new Mao("黄色",4);
System.out.println("颜色:"+m1.getColor()+",腿:"+m1.getLeg());
m1.chifan();
m1.catchMouse();
System.out.println("-----------------------------");
Dog d = new Dog();
d.setColor("黑色");
d.setLeg(4);
System.out.println("颜色:"+d.getColor()+",腿:"+d.getLeg());
d.chifan();
d.lookHome();
d.ken();
System.out.println("------------------------------");
Dog d1 = new Dog("灰色",4);
System.out.println("颜色:"+d1.getColor()+",腿:"+d1.getLeg());
d1.chifan();
d1.lookHome();
d1.ken();
}
}
class Animal {
private String color; //颜色
private int leg; //腿
public Animal() {} //空参
public Animal(String color,int leg) { //有参
this.color = color;
this.leg = leg;
}
public void setColor(String color) { //设置颜色
this.color = color;
}
public String getColor() { //获取颜色
return color;
}
public void setLeg(int leg) { //设置腿
this.leg = leg;
}
public int getLeg() { //获取腿
return leg;
}
public void chifan() {
System.out.println("吃饭");
}
}
class Mao extends Animal {
public Mao() {}
public Mao(String color,int leg) {
super(color,leg);
}
public void catchMouse() {
System.out.println("抓老鼠");
}
public void chifan() {
System.out.println("爱吃鱼");
}
}
class Dog extends Animal {
public Dog() {}
public Dog(String color,int leg) {
super(color,leg);
}
public void lookHome() {
System.out.println("看家");
}
public void ken() {
System.out.println("啃骨头");
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2