package firstchapter;
/**
* 多态中成员变量与成员属性的特点
*/
public class polymorphic {
public static void main(String[] args) {
// 多态成员变量 : 编译运行看左边
Father father = new Child();
System.out.println(father.age);
// 多态成员方法: 编译看左边,运行看右边
Father father1 = new Child();
father1.show();
}
}
class Father {
int age = 43;
public void show() {
System.out.println("父亲的年龄是" + age);
}
}
class Child extends Father{
int age = 23;
public void show() {
System.out.println("孩子的年龄是" + age);
}
}
结果:
43
孩子的年龄是23