jvm視角看java繼承和多型
阿新 • • 發佈:2019-02-15
package test.xing; class Father{ protected int age; public Father(){ age = 40; } void eat(){ System.out.println("父親在吃飯"); } } class Child extends Father{ protected int age; public Child(){ age = 18; } void eat(){ System.out.println("孩子在吃飯"); } void play(){ System.out.println("孩子在打CS"); } } public class TestPolymorphic { public static void main(String[] args) { Father c = new Child(); c.eat(); //c.play(); System.out.println("年齡:"+c.age ); } }