how do you implement an interface in java code example
Example 1: java implement interface
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) {
}
}
Example 2: interface in java
public class MammalInt implements Animal {
public void eat() {
System.out.println("Mammal eats");
}
public void travel() {
System.out.println("Mammal travels");
}
public int noOfLegs() {
return 0;
}
public static void main(String args[]) {
MammalInt m = new MammalInt();
m.eat();
m.travel();
}
}
Example 3: 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