How can i access a static variable by a class name in Java? -



How can i access a static variable by a class name in Java? -

i have many classes have same static attribute (staticattr) , have class accepts class name , accesses staticattr of class name specified. how can this. please help me! thanks.

edit:

public class group_name1 extends activity implements view.onclicklistener, { public static group_name1 staticvar; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.group_name1); staticvar = this; } } public class group_name2 extends activity implements view.onclicklistener, { public static group_name2 staticvar; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.group_name2); staticvar = this; } }

now problem have access static variable of these classes in class giving class name string. class should can used staticvar contains object.

currently, have created seperate classes every class mentioned above refer staticvar. sense redundant , bad style of programming because every class write refering above classes same function. thing changes class name reference

group_name1 grpactivity; group_name2 grpactivity;

these current implementations. want utilize class name refer static variable

class groupnamelistener1 extends thread { group_name1 grpactivity; public void run() { grpactivity = group_name1.staticvar; /* */ } } class groupnamelistener2 extends thread { group_name2 grpactivity; public void run() { grpactivity = group_name2.staticvar; /* */ } }

like :

classwithstaticvariable.variablename

if have

class { public static string = "test" }

then can access :

class b { public void test() { system.out.println(a.a); } }

java class oop

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -