• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt in has-a relationship

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes o is reference variable for OtherClass class and instance variable for
Test class.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic