java - Within object B, how to access an object A that has created object B? -
my code of form below:
public class outer { protected int data; protected inner inner; protected void run() { inner = new inner(); } } public class inner extends outer { protected getouterdata() { ... } } an inner object created within method of class outer. within inner object, there way access data of instance of class outer has created inner object?
edit: realise can pass outer object inner object via constructor wondering if there way?
edit2: passing object via constructor ok i'm doing.
public class outer { protected int data; protected inner inner; protected void run() { inner = new inner(this); } } public class inner extends outer { private outer parent; inner(outer parent) { this.parent = parent } protected getouterdata() { return parent; } }
Comments
Post a Comment