• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help on object references understanding...  RSS feed

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One !!!

Two references, both pointing to the same single object.
 
Wee Keong Soh
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!