-
Notifications
You must be signed in to change notification settings - Fork 0
/
program 8 (vehicle)
74 lines (70 loc) · 1.24 KB
/
program 8 (vehicle)
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
Question:
- Create an interface
vehicle and classes like
bicycle,
car, bike etc, having
common functionalities
and put
all the common
functionalities in the
interface. Classes
like Bicycle, Bike, car etc
implement all these
functionalities in their
own class in their own
way
code:
interface vehicle{
void start();
void stop();
void max_speed();
}
class bicycle implements vehicle{
public void start(){
System.out.println("Starting Bicycle");
}
public void stop(){
System.out.println("Stopping bicycle..");
}
public void max_speed(){
System.out.println("max speed is 15km/hr");
}
}
class car implements vehicle{
public void start(){
System.out.println("Starting car");
}
public void stop(){
System.out.println("Stopping car..");
}
public void max_speed(){
System.out.println("max speed is 80km/hr");
}
}
class truck implements vehicle{
public void start(){
System.out.println("Starting truck");
}
public void stop(){
System.out.println("Stopping truck..");
}
public void max_speed(){
System.out.println("max speed is 60 km/hr");
}
}
class Main{
public static void main(String args []){
vehicle b = new bicycle();
vehicle c=new car();
vehicle t=new truck();
b.start();
b.stop();
b.max_speed();
c.start();
c.stop();
c.max_speed();
t.start();
t.stop();
t.max_speed();
}
}