Object References and Assignment Statements Object References The
Object References and Assignment Statements
Object References • The next 2 o slides are screen shots from the “OOPAssignments. And. References” program available in Resources/Lecture Materials/Assignment 3 Lecture Materials. • They provide the background needed to answer the “OOP” questions in online quiz 6. 2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
PRACTICE! 23
Answers • Question 1: b. Name is “Moose Hunter”. Since the line “Dim d As Puppy = b” set d to point to the same object as b, changing d’s Name will change b’s property. This is the same as saying that the president’s puppy has a new name. You would assume that Obama’s puppy also has a new name. • Question 2: 11. 2. Just like question 1—b and d are the same object; changing the property of one changes it for both. • Question 3: 11. 2. This is a simple value assignment. We haven’t set a=b; we just copy b’s weight into a’s weight. 24
Object Reference Summary • Since object variables reference the address of objects, assignment statements work differently for them. • In addition to simple variable names like x, objects can be referenced as array elements, or as members of collections. • Objects which have no references to them are “orphaned”, and will eventually be removed from memory since there is no way for the program to access them. 25
- Slides: 25