- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestComposite.java
More file actions
Latest commit
38 lines (38 loc) · 517 Bytes
/
Copy pathTestComposite.java
File metadata and controls
38 lines (38 loc) · 517 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
/*
组合
在类里面调用其他类作为成员。
功能与继承相似
*/
classAnimal
{
publicvoidbreath()
{
System.out.println("呼一口气,吸一口气,呼吸中...");
}
}
classBird
{
privateAnimala = newAnimal();
// public Bird(Animal a)
// {
// this.a = a;
// }
publicvoidfly()
{
System.out.println("厉害吧,爷会飞!");
}
publicvoidbreath()
{
a.breath();
}
}
publicclassTestComposite
{
publicstaticvoidmain(String[] args)
{
// Animal a = new Animal();
Birdb = newBird();
b.breath();
b.fly();
}
}