-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterfaces.java
More file actions
49 lines (41 loc) · 1.35 KB
/
Interfaces.java
File metadata and controls
49 lines (41 loc) · 1.35 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
//Interface is a point where two System meet or Interact
interface Bicycle{
int a=45;
void applyBrake(int decrement);
void Speedup(int increment);//Forcefully applying this for implementation
}
interface BlowHorn{
void BlowHorn1();
void BlowHorn2();
}
class Avon implements Bicycle , BlowHorn{//Now any how we have to implement Both the function of the Interface Class
int speed=7;
public void applyBrake(int decrement) {
speed=speed-decrement;
System.out.println("Decrement Speed is "+speed);
}
public void Speedup(int increment) {
speed=speed+increment;
System.out.println("Incremented Speed is "+ speed);
}
public void BlowHorn1() {
System.out.println("Get Away");
}
public void BlowHorn2() {
System.out.println("Come Close");
}
}
public class Interfaces {
public static void main(String[] args) {
//Abstract class vs interfaces
//We cannot extend multiple abstract classes but we can implement multiple interfaces at a time
Avon cycleHarry= new Avon();
cycleHarry.applyBrake(12);
// You can create properties in the interface
System.out.println(cycleHarry.a);
//you cannot modify the properties of interfaces AS they are final
// cycleHarry.a=45
cycleHarry.BlowHorn1();
cycleHarry.BlowHorn2();
}
}