Page 1 of 1

About Question enthuware.ocpjp.v7.2.1385 :

Posted: Fri Apr 17, 2015 5:04 pm
by ThufirHawat
I don't understand :
"More than one inner instance can be associated with the same outer instance."

Can we have an example or something?

Re: About Question enthuware.ocpjp.v7.2.1385 :

Posted: Fri Apr 17, 2015 8:31 pm
by admin

Code: Select all

public class TestClass{
  class Inner{
  }
  public static void main(String args[]) {
    TestClass tc = new TestClass();
    Inner i1 = tc.new Inner(); 
    Inner i2 = tc.new Inner(); 

  }
    
}

Re: About Question enthuware.ocpjp.v7.2.1385 :

Posted: Mon Nov 23, 2015 3:42 pm
by fariz.siracli
" Member variables of the outer instance can always be referred to using only the variable name within the inner instance. "

very difficult sentence. could you explain it, please?

Re: About Question enthuware.ocpjp.v7.2.1385 :

Posted: Mon Nov 23, 2015 7:40 pm
by admin

Code: Select all

public class TestClass{
   int outer;
  class Inner{
     public void m(){
          System.out.println(outer); //accessing outer with just the name. You can do TestClass.this.outer as well.
      }
  }
    
}