Ok, I’m going the spare you the Why this question comes to mind, but I’m still going to ask the question. Can Elephants Jump?  I just put that question into Facebook / twitter as this Chapter starts out talking about putting a Giraffe into a Rabbit variable.  and calling Rabbit hopper = new Giraffe(); .  So I thought yeah, might be interesting seeing a Giraffe hopping, but then thought oooh what would be even cooler was seeing a Elephant jump… If they could how much would the ground shake?  Ok Back to java.

Variables in themselves are pretty straight forward until they talk about Object reference variables.  I think I know what they mean, but the examples they are giving are not helping at all. So I’m stuck trying to sort though what is correct.  It’s these times that I wish I had a Instructor or at least a mentor that can say ok that example is causing more confusion, here look at it THIS way, until it finally make sense.  Or they could listen to what I’m thinking and say yep, you actually got it, ignore that example.

What I’m looking at is this.

Horse a = new Horse();
Horse b = new Horse();

To me, I’m looking at 2 instances of the object Horse.  One instance is called “a” one instance is called “b”. And lets say I sent some color Instance Variable on “a” to be red and on “b” it’s brown.  Let me Show the whole Code:

Horse a = new Horse();
Horse b = new Horse();

a.haircolor = red;
b.haircolor = brown;

So how I have 2 objects, that are instances of Horse.  According to the book I have 2 Horse Objects, and if I did:

Horse c = b;

To me I would now have 3 instances of the horse object with b and c being exact duplicates of each other.  According to this book though I only have 2 objects as b and c reference the same object.  The difference is, if both b and c are referencing the same object then if I make a change to a variable in b wouldn’t it also be changed in c?

Looks like time to let Google do some walking.