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

Stary Kapec
Ranch Hand

Joined: Dec 04, 2005
Posts: 81
class A {}
class B extends A {}
class C { B b; }

C has-a B, but my doubt is if C has-a A is also true, because B extends A

Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
I would have guessed that C HAS-A A, as B IS-A.
But the reference is actual to a class of type B, therefore I would say C dosnt HAVE-A A.

But that is just my guess, would like to know what others think
[ March 20, 2007: Message edited by: Gavin Tranter ]
Srinivasan thoyyeti
Ranch Hand

Joined: Feb 15, 2007
Posts: 557
Yes. C has A through B, would be more proper.

There is difference in saying "C has A" and "C has A through B."

1)C has A: Here A's methods will work on its data.

2)"C has A through B." : when Method overriding takes place, "B method may include its own data too".

Hope its clear.

Thanks & Regards, T.Srinivasan
SCWCD 1.4(89%), SCJP 5.0(75%)
I agree. Here's the link:
subject: Has-a relationship
It's not a secret anymore!