5.8 继承与多态
多态性指父类的某个方法被其子类重写的时候,可以产生自己的功能行为
//例子:
public class Exmaple5_11_Animal {
void cry() {
}
}
public class Exmaple5_11_Cat extends Exmaple5_11_Animal {
void cry() {
System.out.println("喵······");
}
}
public class Exmaple5_11_Dog extends Exmaple5_11_Animal {
void cry() {
System.out.println("汪······");
}
}
public class Exmaple5_11 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Exmaple5_11_Cat cat = new Exmaple5_11_Cat();
cat.cry();
Exmaple5_11_Dog dog = new Exmaple5_11_Dog();
dog.cry();
}
}
//输出结果:
//喵······
//汪······