Scope of static inner class in java -


i found strange thing today. have following class static inner class.

public class pdto {  private agreement agreement = new agreement();      public static class agreement{         public string agreementname;         public string agreementdescription;         public string currency;     }      public agreement getagreement() {         return agreement;     }      public void setagreement(agreement agreement) {         this.agreement = agreement;     } } 

another class classa has following method :-

private agreement createbillingagreement(pdto payment) {      pdto.agreement billingagreement = payment.getagreement();     agreement agreement = new agreement();     agreement.setname(billingagreement.agreementname);     agreement.setdescription(billingagreement.agreementdescription);     billingagreement.agreementname = "changed agreeement name" ; } 

class b's code calls method of class a

classbservice.createbillingagreement(payment); system.out.println("changed billing agreement name : " + payment.getagreement().agreementname); 

and when print agreement name class classb, value set in createbillingagreement method of class a. how possible.

a static-inner class used access @ same class statically. example:

public class parent{     public static class child{         public void amethod(string s){             system.out.println("hi!" + s);         }     } }  public class anotherclass{     public void anothermethod(){         parent.child.amethod("from anotherclass");     } } 

out:

hi! anotherclass

or in case:

ptdo.agreement          ^ 

this static class


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -