public abstract class Parent {
    
    String name = "parent";

}    



public class Son extends Parent{
    
    public void print(){
        this.name = "son";
        System.out.println(super.name);
        System.out.println(this.name);
    }
    
    public static void main(String[] args) throws InstantiationException, IllegalAccessException {
        Son son = new Son();
        son.print();
    }
    
}


son
son

可以看出,子类中的属性的引用指向的是父类属性的地址。

相关文章:

  • 2021-08-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-23
  • 2022-12-23
  • 2022-01-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案