java - How can I modify a variable throughout the chain of calling of class through it's objects? -


i have 3 classes.

class clientconnect(){     url url = new url("http:xxx.xx.xx");     api api = new api(url);     api.checks.count(); }  class api{     ...     url url;     checks checks = new checks(url);     public api(url url){         url = new url(url+"/api");     } }  class checks{     ...     public checks(url url){         url = new url(url+"/checks");     }     public void count(){         url = new url(url+"/count");         system.out.println(url);     } } 

i want output of calling of api.checks.count() http:xxx.xx.xx.xx/api/checks/count , getting null. how can carry forward modified url next chain of class. yeah, can in other ways too, want chain these using objects of classes only.

the issue lies in api class, want modified url sent there while creating object of checks class inside.

modify api constructor, , pass url url constructor after initialize url (and pointed out @jonk in comments, should this.url). like,

url url; checks checks; // <-- url null. public api(url url){     this.url = new url(url+"/api");     checks = new checks(this.url); // <-- url initialized. } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -