-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterFaces.java
More file actions
54 lines (41 loc) · 1017 Bytes
/
Copy pathInterFaces.java
File metadata and controls
54 lines (41 loc) · 1017 Bytes
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
/*
* Interfaces
* -> All methods are public, abstract & without implementation
* -> Used to achieve total abstraction
* -> Variables in the interface are final, public and static
*
*/
public class InterFaces {
public static void main(String[] args) {
Queen q = new Queen();
q.moves();
}
}
interface ChessPlayer{
void moves();
}
class Queen implements ChessPlayer {
public void moves () {
System.out.println("up , down , left , right , diagonal ( in all 4 dirns )");
}
}
class Rook implements ChessPlayer {
public void moves () {
System.out.println("up , down , left , right");
}
}
class King implements ChessPlayer {
public void moves () {
System.out.println("up , down , left , right , diagonal -( by 1 step )");
}
}
interface Herbivore{
}
interface Carnivore {
}
class Bear implements Herbivore, Carnivore{
}
/*
* Output
* up , down , left , right , diagonal ( in all 4 dirns )
*/