-
Notifications
You must be signed in to change notification settings - Fork 0
/
A_39_default_methods.java
63 lines (52 loc) · 1.68 KB
/
A_39_default_methods.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
package com.company;
interface Camera{
void takeSnap();
void recordVideo();
//Default methods enable us to add new functionality to existing interfaces.
private void greet(){
System.out.println("Good Morning");
} //this method can not call direct in main method because it has private access to the Camera Interface
default void record4KVideo() {
greet(); // Interfaces can also include private method for default methods in use
System.out.println("Recording in 4K...");
}
}
interface Wifi{
String[] getNetworks();
void connectToNetwork(String Network);
}
class CellPhone{
void callNumber(int PhoneNumber){
System.out.println("Calling" + PhoneNumber);
}
void pickCall(){
System.out.println("Connecting....");
}
}
class SmartPhone extends CellPhone implements Camera , Wifi{
public void takeSnap() {
System.out.println("Taking Snap....");
}
public void recordVideo(){
System.out.println("Recording Video...");
}
public String[] getNetworks(){
System.out.println("Getting list of networks...");
String[] networkList = {"DJ" , "AP" , "LD"};
return networkList;
}
public void connectToNetwork(String Network){
System.out.println("connecting to" + Network);
}
}
public class A_39_default_methods {
public static void main(String[] args) {
SmartPhone S = new SmartPhone();
S.record4KVideo();
//S.greet(); // ---> Throws an error because greet() has a private access in Camera interface
String[] arr = S.getNetworks();
for (String item:arr) {
System.out.println(item);
}
}
}