android - Aessing public variable in java -
i have create public variable in fouractivity , access in finalactivity class value of variable show 0. have been create getrandomnumber function in fouractivity class return integer.
public int i; i=getrandomnumber(); // accessing variable in finalactivity class through way fouractivity fouractivity=new fouractivity(); int randomnumber=fouractivity.i; toast.maketext(finalactivity.this,"random number" +randomnumber ,toast.length_short).show();
i
not static, therefore when write :
fouractivity fouractivity=new fouractivity(); int randomnumber=fouractivity.i;
you uninitialized value of i
new fouractivity
instance created.
i=getrandomnumber();
updated difference isntance of fouractivity
.
Comments
Post a Comment