描述: 當父類和子類中同時擁有相同名字的 public 變量時,會出現父類字段被隱藏的狀況。code
public class Parent{ public String name = "parent"; } public Child extends Parent{ public String name = "child"; }
... Child c = new Child(); Parent p = c; ...
打印c和p的name值,c.name 是 child ,p.name 是 parentclass