package com.fy.day12.test;
public class Test1 {
public static void main(String[] args) {
Son son = new Son();
son.method();
}
}
class Father{
int filed = 10;
String flag = "Hello";
}
class Son extends Father{
int filed = 20;
public void method() {
System.out.println(super.filed);//在子类中访问父类的成员
System.out.println(this.filed);
System.out.println(flag);
}
}
父子类的同名属性不存在重写关系,两块空间同时存在(子类遮蔽父类属性),需要使用不同前缀进行访问(super/this)
最新推荐文章于 2022-02-12 16:42:29 发布