在父类中访问子类的成员变量public class Father {private String fatherpublic Father() {Field fs[]
在父类中访问子类的成员变量
public class Father {
private String father;
public Father() { Field fs[] = this.getClass().getDeclaredFields(); for (int i = 0; i < fs.length; i++) { Field f = fs[i]; System.out.println(f.getType().getName() + " " + f.getName()); } }
}
public class Son extends Father {
private int age; private String name;
public Son() { super(); // TODO Auto-generated constructor stub }
}
public class Test {
/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Son son = new Son(); }