define a custom interface jav code example

Example 1: define a custom interface jav

// 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: define a custom interface jav

interface methods{
 public static hey(); 
}

class scratch implements methods{
  // Required to implement all methods declared in an interface 
  // Or else the class becomes abstract
  public static hey(){
   System.out.println("Hey"); 
  }
}

Tags:

Java Example