多态01

//动物类:父类
public class Animal {

//移动的方法
public void move(){
System.out.println("动物在移动!!!");
}
}

=========================================
//猫类,子类
public class Cat extends Animal {

//对move方法进行重写
public void move(){
System.out.println("cat 走猫步");
}

//猫除了move之外,应该有自己特有的行为,例如抓老鼠。
//这个行为是子类型对象特有的方法。
public void catchMouse(){
System.out.println("猫正在抓老鼠!!!!!");
}
}
=========================================
//鸟儿类,子类
public class Bird extends Animal {

//重写父类的move方法
public void move(){
System.out.println("鸟儿在飞翔!!!");
}
//也有自己特有的方法
public void sing(){
System.out.println("鸟儿在歌唱!!!");
}

}
=========================================
//Dog并没有继承Animal
//Dog不是Animal的子类

public class Dog {

}


posted @ 2022-05-16 19:11  开山y  阅读(15)  评论(0编辑  收藏  举报