Changing variables in java -


in following code,

int = 1; int j = + 2; int = 2; 

would 'j' equal 2 after 'i' has been changed 2 or 'j' still equal 1?

when assign value any variable in java, variable changes.

in addition, these particular variables primitives, not reference types. each variable holds value, not reference object might shared among variables.

also, note @gtgaxiola's observation code not compile because of second definition of i. can addressed follows:

int = 1; int j = + 2; = 2; 

now, if variables references mutable objects, assign 2 references same object, , change object through either reference.

colorrgb = new colorrgb(0,0,0); colorrgb b = a; a.r = 255; 

here, both a.r , b.r have value of 255, because both referring field in same object.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -