Copying Numbers – Intro to Java Programming


The answer is luckyNumber is 13, and luckyNumber2 is 12. Let’s draw the diagram again. luckyNumber is an int, so instead of having a reference, it just contains the number itself. So initially, we set it to 13. Then we made luckyNumber2 by copying the value of luckyNumber1. Which isn’t a reference this time. It’s just 13. So, luckyNumber2 became 13, then we change the value of luckyNumber2. We set it equal to 12 instead of 13. Since this isn’t a reference, we just reset it to 12, and that’s how we get our answer. Again, ints aren’t objects. Strings are objects. Rectangles are objects. Ints are not objects.

Leave a Reply

Your email address will not be published. Required fields are marked *