aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Help me this code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Help me this code " Watch "Help me this code " New topic
Author

Help me this code

Karu Raj
Ranch Hand

Joined: Aug 31, 2005
Posts: 481
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
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 .

###############################################33
Agrah Upadhyay
Karu Raj
Ranch Hand

Joined: Aug 31, 2005
Posts: 481
ho right

static variable means one value been shared for all instance

ok thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help me this code