forked from slgobinath/Java-Helps-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterfaceMethods.java
More file actions
39 lines (35 loc) · 787 Bytes
/
InterfaceMethods.java
File metadata and controls
39 lines (35 loc) · 787 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
/**
* An interface can have default methods and static methods.
* Any other methods are public and abstract by default.
*
* @author L.Gobinath
*/
public class InterfaceMethods {
public static void main(String[] args) {
Super obj = new Base();
obj.print();
obj.doStuff();
Super.sayHello();
}
}
interface Super {
/**
* An abstract method. By default it is public and abstract.
*/
void print();
public default void doStuff() {
System.out.println("Hello world");
}
public static void sayHello() {
System.out.println("Hello");
}
}
class Base implements Super {
/**
* Override the abstract method.
*/
@Override
public void print() {
System.out.println("Base");
}
}