forked from akash-coded/C133-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterfaces.java
61 lines (48 loc) · 1.13 KB
/
Interfaces.java
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
interface Vehicle {
void start();
void stop();
int getNoOfWheels();
default void displaySpeed() {
System.out.println(getSpeed());
}
static void displayMessage(String msg) {
System.out.println("Message from static function" + msg);
}
private String getSpeed() {
return "new message 2";
}
}
class Car implements Vehicle {
public void start() {
System.out.println("Vehicle started");
}
public void stop() {
System.out.println("Vehicle stopped");
}
public int getNoOfWheels() {
return 4;
}
void performWheelie() {
System.out.println("Wheelies are dangerous");
}
}
class Motorcycle implements Vehicle {
public void start() {
System.out.println("Bike started");
}
public void stop() {
System.out.println("Bike stopped");
}
public int getNoOfWheels() {
return 2;
}
}
class Interfaces {
public static void main(String[] args) {
Vehicle c = new Car();
c.start();
System.out.println(c.getNoOfWheels());
c.displaySpeed();
c.stop();
}
}