在多肽的情况下,就是父类应用指向子类事例。- class Fu {
-
- int x = 1;
- Fu(){
- System.err.println(x+"Fu");
- }
- public void show(){
- System.out.println("我是父类");
- }
- }
- class Zi extends Fu{
- int x = 2;
- Zi(){
- System.out.println(x+"Zi");
- }
- public void show(){
- System.out.println("我是子类");
- }
- }
- class Duotai{
- public static void main(String[] args) {
- Fu fu = new Zi();
- fu.show();
-
- }
- }
复制代码 运行结果是“我是子类”, |