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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -