Repository navigation
Expand file tree
/
Copy pathinterfaces.java
More file actions
86 lines (66 loc) · 1.39 KB
/
Copy pathinterfaces.java
File metadata and controls
86 lines (66 loc) · 1.39 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package courseUd;
interface camera{
void shutter();
void click();
void record();
}
interface musicPlayer{
void play();
void pause();
void stop();
}
class Phone{
void call() {
System.out.println("Calling...");
}
void sms() {
System.out.println("Hiii!!");
}
}
class smartPhone extends Phone implements musicPlayer, camera{
@Override
public void shutter() {
System.out.println("Guess the shutter speed?!!");
}
@Override
public void click() {
System.out.println("Click for an picture!!");
}
@Override
public void record() {
System.out.println("Click here to record!!");
}
@Override
public void play() {
System.out.println("Playing music...");
}
@Override
public void pause() {
System.out.println("Pause.");
}
@Override
public void stop() {
System.out.println("Stop!");
}
}
public class interfaces {
public static void main(String[] args) {
smartPhone sp = new smartPhone();
// ✅ Phone operations
sp.call();
sp.sms();
// ✅ Camera operations
sp.shutter();
sp.click();
sp.record();
// ✅ MusicPlayer operations
sp.play();
sp.pause();
sp.stop();
Phone p = new smartPhone(); //UpCasting - Phone reference, SmartPhone object
p.sms();
p.call();
camera c = sp;
c.click();
}
}