-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCompositionDemo.java
More file actions
46 lines (44 loc) · 898 Bytes
/
CompositionDemo.java
File metadata and controls
46 lines (44 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class Employee{
Account account ;
// Employee(){
// System.out.println("Employee Born...");
// account = new Account(); // Composition
// }
Employee(Account account){
System.out.println("Employee Born...");
this.account = account;
}
@Override
public void finalize(){
System.out.println("Good Bye Employee...");
}
}
class Account
{
Account(){
System.out.println("Account Born....");
}
@Override
public void finalize(){
System.out.println("Good Bye Account...");
}
}
public class CompositionDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Account account = new Account();
Employee ram = new Employee(account);
// if(10>2)
// {
// Employee ram = new Employee();
// }
// }
// Employee shyam = new Employee();
//ram = shyam;
ram = null;
System.gc();
for(int i = 1;i<=10 ; i++){
System.out.println("I is "+i);
}
}
}