Hi!
Having studied a bit of programming years back (bit of Basic and Pascal) I\'m currently trying to learn Java using BlueJ and don\'t quite understand what is going on in one particular situation! My previous programming experience leads me to expect a totally different answer!
The problem is that I have some code that looks like this:
[CODE=Java]
Bird beaky = new Bird ();
beaky.setWingsp an (4);
Bird puffy = beaky;
beaky.setWingsp an (6);
[/CODE]
All the classes and methods are set up and the program executes fine but when I poll the variables after executing I would have expected puffy\'s wingspan to be 4 and beaky\'s to be 6 - in fact they both have a wingspan of 6. Can anyone explain to me why this is?
Thank you in advance for your help! It\'s a silly little question but it\'s got me totally flummexed!
Jay
Having studied a bit of programming years back (bit of Basic and Pascal) I\'m currently trying to learn Java using BlueJ and don\'t quite understand what is going on in one particular situation! My previous programming experience leads me to expect a totally different answer!
The problem is that I have some code that looks like this:
[CODE=Java]
Bird beaky = new Bird ();
beaky.setWingsp an (4);
Bird puffy = beaky;
beaky.setWingsp an (6);
[/CODE]
All the classes and methods are set up and the program executes fine but when I poll the variables after executing I would have expected puffy\'s wingspan to be 4 and beaky\'s to be 6 - in fact they both have a wingspan of 6. Can anyone explain to me why this is?
Thank you in advance for your help! It\'s a silly little question but it\'s got me totally flummexed!
Jay
Comment