子类访问父类的成员变量
parent 类
package cn.zack.five;
import lombok.Data;
/**
* @author: 戴志超
* @date: 2021/4/4 上午12:09
*/
@Data
public class Parent {
public String tag = "疯狂java讲义";
}
derived 子类
package cn.zack.five;
import lombok.Data;
/**
* @author: 戴志超
* @date: 2021/4/4 上午12:09
*/
@Data
public class Derived extends Parent{
public String tag = "轻量级java ee 企业实战";
}
package cn.zack.five;
/**
* @author: 戴志超
* @date: 2021/4/4 上午12:09
*/
public class HideTest {
public static void main(String[] args) {
Derived d = new Derived();
System.out.println(d.tag);
System.out.println(((Parent)d).tag);
}
}