Professional Documents
Culture Documents
Inheritance Association
• Is-A • Is-A
• extends • Reference variable, new
• Blood relation • No Blood relation
• Tightly coupled • Not Tightly coupled
Association
• Association establishes a relationship between any two objects.
• Objects have an independent lifecycle i.e.) no ownership between the objects.
Association
Defense
Minister-1
Finance
External
Prime Affairs
Country Minister-2 People
Minister
Internal
Affairs
Minister-n
More…
Association
Association
Aggregation
Composition
Association
CAR
St
k ro
ea ng
W
Music_Player Engine
Aggregation Composition
Association
University
Is-A Is-A
Professor Branches
[Weak] (Mech, EEE, CSE)
[Strong]
1
// Predict the output
2
import java.util.*;
3
class Company
4
{
5
private String name;
6
Company(String name) {
7
this.name = name;
8
}
9
public String getCompanyName() {
10
return this.name;
11
}
12
}
13
class Employee
14
{
15
private String name;
16
Employee(String name){
17
this.name = name;
18
}
19
public String getEmployeeName() {
20
return this.name;
21
}
22
1 public class Association
2 {
3 public static void main (String[] args)
4 {
5 Scanner sc = new Scanner(System.in);
6 String c_name = sc.next();
7 String e_name = sc.next();
8 Company c = new Company(c_name);
9 Employee emp = new Employee(e_name);
10 System.out.println(emp.getEmployeeName() + " is employee of " +
11 c.getCompanyName());
12 }
13 }
14
15
16
17
18
19
20
21
22
Composition
It represents part – of relationship
Example: