public class Red { private int a; public static int b; public static void main (String[] args) { Red r1 = new Red (),r2=new Red(); r1.a++; r1.b++; System.out.println(r1.a+","+r1.b+","+r2.a+","+r2.b ); } }
The output i got is 1 ,1,0,1.
why is the r2.b is 1 and also for r2.a is 1??
This means instance can increament the static variable .............
agrah upadhyay
Ranch Hand
Joined: Sep 01, 2005
Posts: 579
posted
0
Yaa Instance Variables Can Change The Value Of Static Variables if it is not final.If Changed That Value Exists For Every Instance Of The Class .
<i>--Agrah Upadhyay--</i><br />Final Year B.Tech SCJP,SCWCD,SCBCD <br /> <br /><b>Now since the real test for any choice is having to make the same choice again,knowing full well what it might cost.</b>-Oracle
Karu Raj
Ranch Hand
Joined: Aug 31, 2005
Posts: 479
posted
0
ho right
static variable means one value been shared for all instance
ok thanks
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.