示例代码对象的方法:访问字段和包含“这”对象
public class A {
B b = new B();
int a = 17;
}
public class B {
int getA() {
// how to get 'a' field from object containing 'this' object
}
}
我的问题是,如在样品代码注释。一般来说:如何从包含'this'对象的对象访问字段和方法。 在我的示例中,类B将仅作为A类中的字段实例化。