Java : use string parameter of function as an object name? -


so i'm learning java , don't know how use string object name.

for example, let's suppose have 3 objects not belonging same class, have variables a, b, c. want function modify these variables, depending on object name give, work :

public void myfonction(string objectname) {    objectname.a++; //of course doesn't word    objectname.b=15; //ect } 

this must extremely simple do, found on subject didn't fit case or didn't understand :)

what want not done in java.

it done this:

public class parent {     protected int a;    protected int b;    protected int c; } 

then have

public class extends parent {    //add whatever else need }  public class b extends parent {    //add whatever else need }  public class c extends parent {    //add whatever else need } 

and method be:

public void myfonction(parent object) {    object.a++;    object.b=15;  } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -