forked from navinreddy20/Javacode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14.1 Need of Interface.java
96 lines (78 loc) · 1.39 KB
/
14.1 Need of Interface.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
abstract class Computer
{
// public void code()
// {
//
// }
public abstract void code();
}
class Laptop extends Computer
{
public void code()
{
System.out.println("code, compile, run");
}
}
class Desktop extends Computer
{
public void code()
{
System.out.println("code, compile, faster");
}
}
class Developer
{
// public void devApp(Laptop lap)
public void devApp(Computer lap)
{
lap.code();
}
}
public class Demo {
public static void main(String[] args) {
// Laptop lap=new Laptop();
// Desktop desk=new Desktop();
Computer lap=new Laptop();
Computer desk=new Desktop();
Developer navin=new Developer();
navin.devApp(lap);
}
}
*/
interface Computer
{
void code();
}
class Laptop implements Computer
{
public void code()
{
System.out.println("code, compile, run");
}
}
class Desktop implements Computer
{
public void code()
{
System.out.println("code, compile, faster");
}
}
class Developer
{
// public void devApp(Laptop lap)
public void devApp(Computer lap)
{
lap.code();
}
}
public class Demo {
public static void main(String[] args) {
// Laptop lap=new Laptop();
// Desktop desk=new Desktop();
Computer lap=new Laptop();
Computer desk=new Desktop();
Developer navin=new Developer();
navin.devApp(lap);
}
}