This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

has-a relationship  RSS feed

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A question from SCJP K & B Master exam C :

which statements are true:

..

among the statements, One is :"Has-A relationships always rely on instance variables "(this according to the answer is true)

What about static variables? if a class has static variable is it not considered to be a has-a relationship? can anyone explain??


another question that i want to clarify: consider the following code written by me:




1). Is it a has-a relationship (class A has- a Integer) since Integer is in the standard API. ???

2). If we are looking for coupling then class A and Integer are not tightly coupled because Integer is in standard API . correct or not ??
 
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's from an OOP perspective that we most often talk about "has-a" and "is-a"
relationships. So though you are technically correct, that a class also will have
variables and constants, the preferred answer talks about objects and inheritance.

Jim...
 
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static variables are class level variables and are initialized before the actual class object, is created. Jim is right, and it can be a little confusing but has-a and is-a jargon refers to the instantiation of objects on the heap and from the perspective any relationships between those objects such as in inheritance. In this sense a class object once instantiated as an object doesn't own static variables, they belong to the class itself and as such are shared by ALL instances of the class, not just one class object.

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!