forked from BruceEckel/OnJava8-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrivateInterfaceMethods.java
More file actions
54 lines (49 loc) · 982 Bytes
/
PrivateInterfaceMethods.java
File metadata and controls
54 lines (49 loc) · 982 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// interfaces/PrivateInterfaceMethods.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// {NewFeature} Since JDK 9
interface Old {
default void fd() {
System.out.println("Old::fd()");
}
static void fs() {
System.out.println("Old::fs()");
}
default void f() {
fd();
}
static void g() {
fs();
}
}
class ImplOld implements Old {}
interface JDK9 {
private void fd() { // Automatically default
System.out.println("JDK9::fd()");
}
private static void fs() {
System.out.println("JDK9::fs()");
}
default void f() {
fd();
}
static void g() {
fs();
}
}
class ImplJDK9 implements JDK9 {}
public class PrivateInterfaceMethods {
public static void main(String[] args) {
new ImplOld().f();
Old.g();
new ImplJDK9().f();
JDK9.g();
}
}
/* Output:
Old::fd()
Old::fs()
JDK9::fd()
JDK9::fs()
*/