| Author |
Help on object references understanding...
|
Wee Keong Soh
Greenhorn
Joined: Apr 08, 2009
Posts: 18
|
|
Hi,
class Dog {
Cat c = new Cat();
}
class Cat {
//blah blah blah
}
Dog d = new Dog();
Dog a;
a = d;
im aware that the Dog object will have 2 references refering to it. But how many references to Cat object will i have?
|
 |
Dawn Charangat
Ranch Hand
Joined: Apr 26, 2007
Posts: 249
|
|
One !!!
Two references, both pointing to the same single object.
|
 |
Wee Keong Soh
Greenhorn
Joined: Apr 08, 2009
Posts: 18
|
|
Hi,
So am i right to say that there will be 1 dog object with 2 references to it, and 1 cat object also with 2 references to it?
Thanks
|
 |
Dawn Charangat
Ranch Hand
Joined: Apr 26, 2007
Posts: 249
|
|
No.
1) 1 Dog object with 2 references to it - correct
2) 1 Cat object with 2 references to it - wrong
The cat object has only 1 reference, that is the dog object.
|
 |
Wee Keong Soh
Greenhorn
Joined: Apr 08, 2009
Posts: 18
|
|
|
ok thanks.
|
 |
 |
|
|
subject: Help on object references understanding...
|
|
|