vikky.ag agrawal wrote:
the value of x should be 2 after invocation of method but it shows 1??
static variable are class variables and each instance points to that same variable then why no increment in x???
Hi Vikky,
we have here variables of the primitive data type int. So nothing points to anywhere. Actually for this problem it doesn't matter if we have instance or static variables.
After the call to the method, copies of the variables are creates and these copies are incremented and not the static variable x or the local variable y: