wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Does is-a imply has-a ? 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 "Does is-a imply has-a ?" Watch "Does is-a imply has-a ?" New topic
Author

Does is-a imply has-a ?

Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
class A { C c = new C(); }
class B extends A {}
1. B has-a C ?
class A { private C c = new C(); }
class B extends A {}
2. B has-a C ?
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Yup.
If B inherits from A, and A has an inheritable member c of type C, then B inherits that member and, therefore, B "has a" C.
In the second case, however, the member is private so it is not inherited. Therefore, in that case, B doesn't have a C.
[ July 18, 2003: Message edited by: Corey McGlone ]

SCJP Tipline, etc.
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Thank you Corey.
I am getting is-a and has-a confused with class diagrams. I was thinking is-a is the inheritance arrow and has-a is the aggregation symbol. I first saw the terms is-a and has-a in the UML User's Guide.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does is-a imply has-a ?