File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes has-a relationship Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "has-a relationship" Watch "has-a relationship" New topic

has-a relationship

saima kanwal
Ranch Hand

Joined: Oct 05, 2009
Posts: 148
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 ??

SCJP 6.0 (86%) SCWCD 5 (94%)
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
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.


Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
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.

be a well encapsulated person, don't expose your privates, unless you public void getWife()!
I agree. Here's the link:
subject: has-a relationship
It's not a secret anymore!