-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface_pratice1.java
More file actions
69 lines (62 loc) · 1.35 KB
/
interface_pratice1.java
File metadata and controls
69 lines (62 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* interface_pratice1
*/
interface Vechile{
void changegrear(int newgear);
void speedup(int newspeed);
void applybreak(int newbreak);
}
class Bicycle implements Vechile{
int speed;
int gear;
@Override
public void changegrear(int newgear){
gear=newgear;
}
@Override
public void speedup(int newspeed){
speed=newspeed;
}
@Override
public void applybreak(int newbreak){
speed=speed-newbreak;
}
public void printStates(){
System.out.println("speed: "+speed+", gear : "+gear);
}
}
class Bike implements Vechile{
int speed;
int gear;
@Override
public void changegrear(int newgear){
gear=newgear;
}
@Override
public void speedup(int newspeed){
speed=newspeed;
}
@Override
public void applybreak(int newbreak){
speed=speed-newbreak;
}
public void printStates(){
System.out.println("speed: "+speed+", gear : "+gear);
}
}
public class interface_pratice1 {
public static void main(String[] args) {
Bicycle b1=new Bicycle();
b1.applybreak(1);
b1.changegrear(5);
b1.speedup(4);
System.out.println("bicycle data is above");
b1.printStates();
Bike c1=new Bike();
c1.applybreak(10);
c1.changegrear(4);
c1.speedup(2);
System.out.println("bike data is above");
c1.printStates();
}
}