Originally posted by Abhi vijay:
In this case, what is the relation between class A and Class C???
SCJP 5.0, SCJD in progress
Originally posted by Thomas Thevis:
a HAS-A relationship between two classes usually means that an instance of one of the classes holds an instance variable of the type of the other variable
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
krmgroups wrote:A LITTLE MORE: HAS-A:
what is 'is a' and 'has a' relationship:
The is a relationship is expressed with inheritance and has a relationship is expressed with composition.
Both inheritance and composition allow you to place sub-objects inside your new class. Two of the main techniques for code reuse are class inheritance and object composition.
e.g.,
is a --- House is a Building
has a -- House has a bathroom
Inheritance Vs Composition
Inheritance is uni-directional. For example House is a Building. But Building is not a House. Inheritance uses
extends key word. Composition: is used when House has a Bathroom. It is incorrect to say House is a Bathroom.
Composition simply means using instance variables that refer to other objects. The class House will have an instance variable
[edit]Add code tags. CR[/edit]
[ September 30, 2008: Message edited by: Campbell Ritchie ]
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |