• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

doubt in has-a relationship

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
true or false:
"Has-a relationships always rely on instance variables."

ans.:true

i am confused that in the following code dog is instance variable or a reference because i think that instance variable is the class attributes( 's' for class Cat)

class Cat{
int s;
Dog dog=new Dog();
}

please meke me clear.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In my opinion, dog is an instance variable of class Cat, which (dog) is a reference to the Dog object. The meaning of instance variable is not limited to a primary data types. It can be any primary data type like int, float etc or it can also be a reference to other objects.

Hope this will help you,

Regards,
Pranav Thakker
 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i think you are confuse between instance variable and reference variable.
In above code there two instance variable
1. x
2. o

now class Test and OtherClass is connected with each other by "has a relationship"
and hence has a relationship relays on instance variables.
 
Vaibhav Chauhan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gowher.... do you mean that o is called instance variable as well as reference variable ??

thanks for all help.
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes o is reference variable for OtherClass class and instance variable for
Test class.
 
He's giving us the slip! Quick! Grab this tiny ad!
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!