I change the value of X Y isn't always
I change the value of X Y isn't always going to get affected allow me display you so I'm gonna replace X to 2 after which print Y so syu t tab y let's take a glance so run as you can see Y isn't always affected because x and y are completely independent of each different however whilst we use a reference time this conduct is special allow's take a glance so I'm gonna delete all the code here in Java we've got a factor elegance this is described in this package Java that awt so we press ENTER and now we've got this import statement on the pinnacle beautiful allow's declare a variable like factor 1 and set it to new factor here we will bypass the preliminary values for x and y so I'm gonna pass 1 and 1 so wise automatically adds those labels x and y now much like before I'm gonna declare some other variable factor 2 and set it to point 1 and this is where matters get thrilling whilst Java Runtime surroundings executes line eight first it's going to allocate a few reminiscence to store this factor object allow's see if the deal with of that reminiscence location is one hundred then it'll allocate a separate a part of the memory and it'll connect this label to that reminiscence vicinity factor 1 in that reminiscence vicinity it will save the deal with of our point item so this is the critical difference between primitive and reference kinds while we claim a primitive variable like a byte the fee that we assigned to that variable could be stored in that reminiscence location but whilst we use a reference type like this factor class our variable is going to hold the ax of that factor object in memory not the actual pointer object now examine line 9 right here we are copying the cost that we have on this variable into this other variable so that cost.
Comments
Post a Comment