-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterfaces.java
More file actions
54 lines (46 loc) · 1.24 KB
/
Copy pathInterfaces.java
File metadata and controls
54 lines (46 loc) · 1.24 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
48
49
50
51
52
53
54
interface Chargeable {
int battery = 69;
void charge();
}
interface Connectable {
void connect();
}
class Smartphone implements Chargeable, Connectable {
@Override
//MUST DECLARE PUBLIC
public void charge() {
System.out.println("Smartphone is charging");
System.out.println("Phone battery is: "+ battery);
}
@Override
public void connect() {
System.out.println("Smartphone is connecting to the network");
}
}
class Laptop implements Chargeable, Connectable {
@Override
public void charge() {
System.out.println("Laptop is charging");
}
@Override
public void connect() {
System.out.println("Laptop is connecting to the Wi-Fi");
}
}
public class Interfaces {
public static void main(String[] args) {
Chargeable myPhone = new Smartphone();
myPhone.charge(); // Outputs: Smartphone is charging
Connectable myLaptop = new Laptop();
myLaptop.connect(); // Outputs: Laptop is connecting to the Wi-Fi
}
}
//no construcots
//no instance variables-variables are public static and final by default
//interface can extend another interface
interface Animal {
void eat();
}
interface Dog extends Animal {
void bark();
}