multiple interface in java code example
Example 1: how to declare a interface in java
interface Appendable {
void append(string content);
}
class SimplePrinter implements Appendable {
public void append(string content) {
System.out.println(content);
}
}
class FileWriter implements Appendable {
public void append(string content) {
}
}
0
how to implement a interface in java
Example 2: reason we can implement multiple interfaces in java
A class can implement any number of interfaces.
In this case there is no ambiguity even
though both the interfaces are having same method.
Because methods in an interface are always
abstract by default, which doesn’t let them
give their implementation
in interface itself.