-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefualt_Method.java
More file actions
30 lines (30 loc) · 964 Bytes
/
Defualt_Method.java
File metadata and controls
30 lines (30 loc) · 964 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
// default method are not compulsory to be overriden
// Interface have abstract method(with no speacial "abstract" keyword.) So they must be overriden
// private and default method have body in interface.
// private method have scope only within its class or interface
// so we can use them in defualt method by calling them there as below
interface cellphone{
void torch();
private void battery(){
System.out.println("battery is 98%");
}
default void call_receiving(){
battery();
System.out.println("receving call");
}
}
class smartphone implements cellphone{
public void torch(){
System.out.println("Turning on torch....");
}
// public void call_receiving(){
// System.out.println("Receiving call in smartphone");
// }
}
public class Defualt_Method{
public static void main(String[] args) {
smartphone s=new smartphone();
s.torch();
s.call_receiving();
}
}