多态的编译,成员变量,运行编译看左边,成员方法运行看右边

package com.ZZ.z1;

class Fu {
int num = 4;
void show() {
System.out.println("showFu");
}
}

class Zi extends Fu {
int num = 5;

void show() {
System.out.println("showZi");
}
}

class T {
public static void main(String[] args) {
Fu f = new Zi();
Zi z = new Zi();
System.out.println(f.num);
System.out.println(z.num);
f.show();
z.show();
}
}

posted @ 2022-05-24 16:31  小松2739  阅读(30)  评论(0编辑  收藏  举报