I learned what this piece of code does, thanks to chapter three. The first half establishes a reference variable named dog1 that is of the Dog type. The second half creates a new dog object and adds it to the "heap". To link the object to the reference, thus assigning the new Dog to the reference variable dog1, the equal sign is used.
dog1.bark();
After the previous line of code, this line ensues, as it give dog1 an action to perform. the first half of the code is the reference variable, while the second half is the action. Basically, the dot operator is used to explain that you use the thing before the dot to do the thing stated after the dot. Thus, this line of code means to use dog1 to invoke the bark method.
With Primitive Variables, the value of the variable is the value, such as 5, -27.9, or 'a'.
With Reference Variables, the value of the variable is the bits representing a way to get to a specific object.
This is a dog.
No comments:
Post a Comment