According from the definition in Wikipedia, has-a (has_a or has a) is a composition relationship where one object (often called the constituted object, or part/constituent/member object) "belongs to" (is part or member of) another object (called the composite type), and behaves according to the rules of ownership. In simple words,
has-a relationship in an object is called a member field of an object. Multiple has-a relationships will combine to form a possessive hierarchy.
There is 3 classes provided:
- class Class1 {
- String v1;
- }
- class Class2 {
- Class1 c1;
- String v2;
- }
- public class Class3 {
- Class2 c1;
- String i3;
- }
1 ) Class3 HAS-A Class2 (line9)
2) Class2 has-a Class1 (line5)
3) Since the string value v1 was initialized at Class 1, (line2)
Class3 HAS-A Class2, (line9)
Class2 HAS-A Class1, (line5)
so Class3 HAS-A string v1 (since each object of Class1 has-a v1.).
No comments :
Post a Comment