interfaces java example
Example 1: java implement interface
// Assume we have the simple interface:
interface Appendable {
void append(string content);
}
// We can implement it like that:
class SimplePrinter implements Appendable {
public void append(string content) {
System.out.println(content);
}
}
// ... and maybe like that:
class FileWriter implements Appendable {
public void append(string content) {
// Appends content into a file
}
}
// Both classes are Appendable.
Example 2: java interface
public interface Exampleinterface {
public void menthod1();
public int method2();
}
class ExampleInterfaceImpl implements ExampleInterface {
public void method1()
{
//code here
}
public int method2()
{
//code here
}
}