-
Notifications
You must be signed in to change notification settings - Fork 0
/
Adapter.java
43 lines (40 loc) · 857 Bytes
/
Adapter.java
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
abstract class Apple {
public abstract void charge();
}
class Iphone {
Apple apple;
Iphone(Apple apple){
this.apple=apple;
}
public void chargePhone()
{
apple.charge();
}
}
abstract class Android {
public abstract void charging();
}
class AndroidCharger extends Android{
@Override
public void charging() {
System.out.println("cahrging using android");
}
}
class AdapterFun extends Apple{
Android android;
AdapterFun(Android android){
this.android=android;
}
@Override
public void charge() {
System.out.println("Adapter using");
android.charging();
}
}
public class Adapter {
public static void main(String[] args) {
Apple a=new AdapterFun(new AndroidCharger());
Iphone iphone=new Iphone(a);
a.charge();
}
}