-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterface.java
More file actions
47 lines (36 loc) · 1.23 KB
/
Interface.java
File metadata and controls
47 lines (36 loc) · 1.23 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
/* Interfaces= It gives 100% data hiding facility
properties:-
1.Interface class initialize with "interface" keyword
2.we can inherit interface class by using "implements" keyword
3.We cannot make constructors in interface class
4.Only abstract methods are allowed in interface class
(optional: we use abstract keyword before method or not it is not compulsary) */
interface Car { //initialize with interface
void mailege();
//Car() = constructor are not possible
abstract void speed(); // we can use abstract or not but all methods are abstract
}
class BMW implements Car { //inherit by using impelemnts
public void mailege() {
System.out.println("7 KMPH");
}
public void speed() {
System.out.println("240/KMPH");
}
}
public class Interface implements Car { //class name is jaguar but for complie run i make this Interface
public void mailege() {
System.out.println("4 KMPH");
}
public void speed() {
System.out.println("320/KMPH");
}
public static void main(String[] args) {
BMW b = new BMW();
b.mailege();
b.speed();
Interface j = new Interface();
j.mailege();
j.speed();
}
}