-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh11_57_InheritanceInInterfaces.java
More file actions
50 lines (38 loc) · 1.47 KB
/
Ch11_57_InheritanceInInterfaces.java
File metadata and controls
50 lines (38 loc) · 1.47 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
public class Ch11_57_InheritanceInInterfaces {
interface Speaker{
void FM(double channel);
void Aux();
}
// Now if we want to make another interface that has Methods of Speaker we can extend it rather than creating new methods
interface Speaker2 extends Speaker{ // Note interface can be extended on other and not implemented.
void USB();
void Bluetooth(String Pairer);
}
// Now to implement both of these we need to create a class bcz objects can't be made from an Interface
static class Sony implements Speaker2{
public void DolbyAtmos(){
System.out.println("Experiencing Dolby surround...");
}
public void FM(double channel){
System.out.println("Tuned to: " + channel);
}
public void Aux(){
System.out.println("AUX mode connected");
}
public void USB(){
System.out.println("USB connnected");
}
public void Bluetooth(String pairer){
System.out.println("BT paired to: " + pairer);
}
}
public static void main(String[] args) {
// Since OOPs is based on DRY principle , Inheritance is introduced in Interfaces.
Sony homeTheatre = new Sony();
homeTheatre.FM(93.5);
homeTheatre.Aux();
homeTheatre.USB();
homeTheatre.Bluetooth("Nokia Lumia");
homeTheatre.DolbyAtmos();
}
}